Market Basket Analysis

Affinity analysis is a data analysis and data mining technique that discovers co-occurrence relationships among activities performed by (or recorded about) specific individuals or groups. In general, this can be applied to any process where agents can be uniquely identified and information about their activities can be recorded. In retail, affinity analysis is used to perform market basket analysis, in which retailers seek to understand the purchase behavior of customers. This information can then be used for purposes of cross-selling and up-selling, in addition to influencing sales promotions, loyalty programs, store design, and discount plans

Example

  1. Market basket analysis might tell a retailer that customers often purchase shampoo and conditioner together, so putting both items on promotion at the same time would not create a significant increase in revenue, while a promotion involving just one of the items would likely drive sales of the other.

  2. one super market chain discovered in its analysis that male customers that bought diapers often bought beer as well, have put the diapers close to beer coolers, and their sales increased dramatically

src: https://en.wikipedia.org/wiki/Affinity_analysis


In [2]:
#Import required libraries
import itertools
import sys
import time
import pandas as pd

In [3]:
def tokenize(file_name):
    # Assumes that sentences are separated by a single '\n'.
    # Assumes that words are separated by a single ' '.
    # Tokenizes each sentence, removes duplicate tokens, sorts tokens.
    return [sorted(list(set(e.split(",")))) for e in
            open(file_name).read().strip(",").split('\n')]

In [4]:
#Run tokenize function on groceries_mba dataset and get the output as shown below
tokenize("../data/groceries_mba.csv")


Out[4]:
[['citrus_fruit', 'margarine', 'ready_soups', 'semi-finished_bread'],
 ['coffee', 'tropical_fruit', 'yogurt'],
 ['whole_milk'],
 ['cream_cheese_', 'meat_spreads', 'pip_fruit', 'yogurt'],
 ['condensed_milk',
  'long_life_bakery_product',
  'other_vegetables',
  'whole_milk'],
 ['abrasive_cleaner', 'butter', 'rice', 'whole_milk', 'yogurt'],
 ['rolls/buns'],
 ['UHT-milk',
  'bottled_beer',
  'liquor_(appetizer)',
  'other_vegetables',
  'rolls/buns'],
 ['pot_plants'],
 ['cereals', 'whole_milk'],
 ['bottled_water',
  'chocolate',
  'other_vegetables',
  'tropical_fruit',
  'white_bread'],
 ['bottled_water',
  'butter',
  'citrus_fruit',
  'curd',
  'dishes',
  'flour',
  'tropical_fruit',
  'whole_milk',
  'yogurt'],
 ['beef'],
 ['frankfurter', 'rolls/buns', 'soda'],
 ['chicken', 'tropical_fruit'],
 ['butter', 'fruit/vegetable_juice', 'newspapers', 'sugar'],
 ['fruit/vegetable_juice'],
 ['packaged_fruit/vegetables'],
 ['chocolate'],
 ['specialty_bar'],
 ['other_vegetables'],
 ['butter_milk', 'pastry'],
 ['whole_milk'],
 ['cream_cheese_',
  'detergent',
  'newspapers',
  'processed_cheese',
  'tropical_fruit'],
 ['bathroom_cleaner',
  'candy',
  'flour',
  'frozen_dessert',
  'other_vegetables',
  'rolls/buns',
  'root_vegetables',
  'salty_snack',
  'sweet_spreads',
  'tropical_fruit',
  'waffles'],
 ['bottled_water', 'canned_beer'],
 ['yogurt'],
 ['chocolate', 'rolls/buns', 'sausage', 'soda'],
 ['other_vegetables'],
 ['brown_bread',
  'canned_beer',
  'fruit/vegetable_juice',
  'newspapers',
  'shopping_bags',
  'soda'],
 ['beverages', 'bottled_water', 'specialty_bar', 'yogurt'],
 ['bottled_water',
  'hamburger_meat',
  'hygiene_articles',
  'napkins',
  'other_vegetables',
  'rolls/buns',
  'spices'],
 ['beverages', 'other_vegetables', 'root_vegetables', 'sugar', 'whole_milk'],
 ['abrasive_cleaner',
  'artif._sweetener',
  'berries',
  'other_vegetables',
  'pork',
  'soda',
  'whipped/sour_cream',
  'whole_milk'],
 ['beef', 'detergent', 'grapes'],
 ['pastry', 'soda'],
 ['fruit/vegetable_juice'],
 ['canned_beer'],
 ['dessert', 'other_vegetables', 'root_vegetables', 'whole_milk'],
 ['citrus_fruit', 'newspapers', 'zwieback'],
 ['canned_beer',
  'rolls/buns',
  'sausage',
  'shopping_bags',
  'soda',
  'specialty_bar'],
 ['brown_bread',
  'candy',
  'cereals',
  'coffee',
  'domestic_eggs',
  'pastry',
  'root_vegetables',
  'soda',
  'sugar',
  'tropical_fruit',
  'waffles',
  'whole_milk',
  'yogurt'],
 ['berries', 'yogurt'],
 ['canned_beer'],
 ['bottled_water',
  'butter_milk',
  'cream_cheese_',
  'newspapers',
  'rolls/buns',
  'soda',
  'spread_cheese',
  'yogurt'],
 ['coffee'],
 ['bottled_water', 'pastry'],
 ['rolls/buns'],
 ['misc._beverages'],
 ['UHT-milk',
  'bottled_water',
  'butter',
  'curd',
  'hard_cheese',
  'long_life_bakery_product',
  'other_vegetables',
  'rolls/buns',
  'root_vegetables',
  'whipped/sour_cream'],
 ['cat_food', 'newspapers', 'rolls/buns', 'sausage'],
 ['canned_beer'],
 ['grapes', 'ham', 'other_vegetables', 'whole_milk'],
 ['baking_powder',
  'brown_bread',
  'curd',
  'domestic_eggs',
  'fruit/vegetable_juice',
  'margarine',
  'other_vegetables',
  'semi-finished_bread',
  'tropical_fruit',
  'turkey'],
 ['pickled_vegetables', 'processed_cheese', 'soda', 'whole_milk', 'yogurt'],
 ['curd', 'pastry', 'whole_milk', 'yogurt'],
 ['brown_bread', 'canned_beer', 'packaged_fruit/vegetables'],
 ['bottled_water',
  'chewing_gum',
  'chocolate_marshmallow',
  'hygiene_articles',
  'napkins',
  'oil',
  'rolls/buns'],
 ['beef', 'cat_food', 'ham', 'ice_cream', 'rolls/buns', 'whipped/sour_cream'],
 ['pastry', 'rolls/buns', 'sugar'],
 ['canned_fish',
  'detergent',
  'frozen_vegetables',
  'other_vegetables',
  'salty_snack',
  'seasonal_products',
  'whole_milk'],
 ['pastry', 'sausage'],
 ['beef', 'sausage', 'whole_milk'],
 ['brown_bread', 'frankfurter', 'rolls/buns', 'sugar', 'tropical_fruit'],
 ['pastry', 'rolls/buns', 'soda'],
 ['whole_milk'],
 ['coffee', 'curd_cheese'],
 ['newspapers', 'red/blush_wine'],
 ['curd', 'sausage', 'whole_milk'],
 ['berries',
  'chocolate',
  'frozen_potato_products',
  'pickled_vegetables',
  'pip_fruit',
  'rolls/buns',
  'tropical_fruit',
  'whole_milk'],
 ['red/blush_wine'],
 ['butter',
  'candles',
  'flower_(seeds)',
  'margarine',
  'specialty_chocolate',
  'specialty_fat',
  'whole_milk'],
 ['citrus_fruit',
  'domestic_eggs',
  'frankfurter',
  'newspapers',
  'oil',
  'sparkling_wine',
  'specialty_chocolate',
  'whole_milk'],
 ['meat_spreads', 'soda', 'whole_milk'],
 ['frozen_potato_products'],
 ['other_vegetables', 'rolls/buns', 'sugar', 'whole_milk'],
 ['butter_milk', 'citrus_fruit', 'curd', 'pastry', 'whole_milk'],
 ['bottled_beer', 'bottled_water', 'flour', 'fruit/vegetable_juice', 'salt'],
 ['bottled_beer', 'bottled_water', 'soda', 'sugar'],
 ['coffee', 'frozen_meals'],
 ['chocolate'],
 ['bathroom_cleaner',
  'canned_vegetables',
  'domestic_eggs',
  'frozen_vegetables',
  'fruit/vegetable_juice',
  'margarine',
  'oil',
  'rolls/buns',
  'root_vegetables',
  'whole_milk'],
 ['frozen_vegetables', 'hard_cheese', 'onions', 'root_vegetables'],
 ['candles',
  'condensed_milk',
  'frozen_vegetables',
  'herbs',
  'oil',
  'salt',
  'white_wine'],
 ['bottled_water'],
 ['brandy',
  'detergent',
  'onions',
  'rolls/buns',
  'root_vegetables',
  'sausage',
  'yogurt'],
 ['coffee', 'newspapers'],
 ['other_vegetables', 'pork', 'whipped/sour_cream'],
 ['berries', 'yogurt'],
 ['soda'],
 ['berries'],
 ['candles', 'fruit/vegetable_juice', 'salty_snack'],
 ['butter_milk', 'citrus_fruit', 'cream_cheese_', 'yogurt'],
 ['berries',
  'chocolate',
  'citrus_fruit',
  'coffee',
  'hamburger_meat',
  'onions',
  'pork',
  'rice',
  'whipped/sour_cream'],
 ['detergent'],
 ['grapes', 'photo/film'],
 ['brown_bread',
  'canned_beer',
  'fruit/vegetable_juice',
  'red/blush_wine',
  'rolls/buns',
  'sausage',
  'shopping_bags',
  'sliced_cheese',
  'waffles'],
 ['butter',
  'chicken',
  'citrus_fruit',
  'detergent',
  'hamburger_meat',
  'oil',
  'other_vegetables',
  'pasta',
  'root_vegetables',
  'tropical_fruit'],
 ['brown_bread', 'whole_milk', 'yogurt'],
 ['citrus_fruit', 'tropical_fruit'],
 ['misc._beverages', 'soda'],
 ['bathroom_cleaner',
  'grapes',
  'pastry',
  'pork',
  'rolls/buns',
  'sausage',
  'soda',
  'specialty_bar',
  'whole_milk'],
 ['bottled_water', 'frankfurter', 'rolls/buns'],
 ['bottled_beer',
  'coffee',
  'fruit/vegetable_juice',
  'napkins',
  'photo/film',
  'sausage',
  'shopping_bags',
  'softener',
  'whole_milk',
  'yogurt'],
 ['soda'],
 ['fruit/vegetable_juice', 'rolls/buns'],
 ['beef',
  'berries',
  'brown_bread',
  'citrus_fruit',
  'detergent',
  'root_vegetables'],
 ['candy',
  'cling_film/bags',
  'rolls/buns',
  'soda',
  'waffles',
  'whipped/sour_cream',
  'whole_milk'],
 ['processed_cheese'],
 ['pip_fruit', 'tropical_fruit'],
 ['bottled_beer',
  'chewing_gum',
  'dishes',
  'frankfurter',
  'oil',
  'other_vegetables',
  'pickled_vegetables',
  'rolls/buns',
  'root_vegetables',
  'sausage'],
 ['bottled_water', 'packaged_fruit/vegetables'],
 ['bottled_water',
  'dessert',
  'frozen_vegetables',
  'margarine',
  'newspapers',
  'red/blush_wine',
  'rolls/buns',
  'whole_milk'],
 ['berries', 'whipped/sour_cream'],
 ['UHT-milk', 'berries', 'citrus_fruit', 'processed_cheese'],
 ['tropical_fruit', 'whole_milk', 'yogurt'],
 ['bottled_beer',
  'frozen_vegetables',
  'hamburger_meat',
  'rolls/buns',
  'sparkling_wine',
  'whole_milk'],
 ['dishes',
  'domestic_eggs',
  'frozen_vegetables',
  'hamburger_meat',
  'other_vegetables',
  'soda',
  'whole_milk'],
 ['cream_cheese_', 'soda', 'whole_milk'],
 ['coffee',
  'fish',
  'long_life_bakery_product',
  'male_cosmetics',
  'margarine',
  'other_vegetables',
  'pastry',
  'shopping_bags'],
 ['frankfurter', 'long_life_bakery_product', 'sausage', 'waffles'],
 ['canned_beer',
  'dessert',
  'packaged_fruit/vegetables',
  'semi-finished_bread'],
 ['pastry', 'soda'],
 ['other_vegetables', 'red/blush_wine'],
 ['misc._beverages'],
 ['canned_fruit',
  'citrus_fruit',
  'cream_cheese_',
  'domestic_eggs',
  'frankfurter',
  'fruit/vegetable_juice',
  'hard_cheese',
  'hygiene_articles',
  'misc._beverages',
  'pip_fruit',
  'rice',
  'sausage',
  'sugar',
  'tropical_fruit',
  'whole_milk'],
 ['sparkling_wine'],
 ['specialty_bar'],
 ['butter_milk', 'rolls/buns', 'sausage'],
 ['curd_cheese'],
 ['dessert', 'frankfurter'],
 ['beverages', 'brown_bread', 'shopping_bags', 'whole_milk', 'yogurt'],
 ['newspapers'],
 ['berries', 'soda'],
 ['curd', 'flour', 'liquor_(appetizer)'],
 ['coffee', 'other_vegetables', 'tropical_fruit'],
 ['soda'],
 ['Instant_food_products', 'rolls/buns'],
 ['canned_beer'],
 ['canned_beer'],
 ['frankfurter', 'margarine', 'rolls/buns', 'sausage', 'whole_milk'],
 ['canned_beer', 'misc._beverages', 'other_vegetables'],
 ['frozen_vegetables', 'whole_milk'],
 ['whole_milk'],
 ['butter',
  'citrus_fruit',
  'cream_cheese_',
  'margarine',
  'newspapers',
  'oil',
  'white_bread'],
 ['frankfurter', 'rolls/buns'],
 ['baking_powder',
  'frankfurter',
  'frozen_vegetables',
  'ham',
  'other_vegetables',
  'pip_fruit',
  'rolls/buns',
  'soft_cheese',
  'sugar',
  'whole_milk'],
 ['butter_milk', 'detergent', 'honey', 'soda', 'yogurt'],
 ['bottled_water',
  'citrus_fruit',
  'dental_care',
  'hamburger_meat',
  'onions',
  'rolls/buns'],
 ['pasta', 'popcorn'],
 ['cake_bar',
  'chocolate',
  'meat_spreads',
  'other_vegetables',
  'shopping_bags',
  'whole_milk'],
 ['candles',
  'citrus_fruit',
  'dessert',
  'dishes',
  'pork',
  'sausage',
  'white_bread'],
 ['rolls/buns'],
 ['curd', 'dessert', 'grapes', 'napkins', 'other_vegetables', 'yogurt'],
 ['beverages',
  'bottled_beer',
  'frozen_vegetables',
  'fruit/vegetable_juice',
  'other_vegetables',
  'root_vegetables',
  'soft_cheese',
  'whole_milk',
  'yogurt'],
 ['coffee', 'shopping_bags'],
 ['popcorn'],
 ['bottled_water', 'rolls/buns', 'soda', 'sugar', 'whole_milk'],
 ['other_vegetables',
  'packaged_fruit/vegetables',
  'snack_products',
  'tropical_fruit',
  'whole_milk'],
 ['beef', 'cling_film/bags', 'flour', 'flower_soil/fertilizer', 'herbs'],
 ['butter', 'dessert', 'rolls/buns', 'whole_milk'],
 ['chewing_gum', 'frankfurter', 'soda'],
 ['bottled_water', 'specialty_cheese', 'tropical_fruit'],
 ['canned_beer'],
 ['bottled_beer',
  'finished_products',
  'frozen_vegetables',
  'other_vegetables'],
 ['beverages', 'soda'],
 ['hamburger_meat', 'root_vegetables', 'whole_milk'],
 ['long_life_bakery_product', 'pastry', 'whole_milk'],
 ['finished_products', 'shopping_bags', 'white_wine'],
 ['other_vegetables'],
 ['bottled_beer',
  'brown_bread',
  'fruit/vegetable_juice',
  'ham',
  'other_vegetables',
  'tropical_fruit',
  'white_bread',
  'whole_milk'],
 ['other_vegetables'],
 ['butter_milk', 'cocoa_drinks', 'curd', 'popcorn', 'salty_snack'],
 ['bottled_beer'],
 ['cake_bar',
  'chocolate',
  'curd',
  'dessert',
  'salty_snack',
  'shopping_bags',
  'soda',
  'waffles'],
 ['cereals', 'cream_cheese_', 'dog_food', 'whole_milk'],
 ['salt', 'whole_milk'],
 ['dessert', 'ice_cream'],
 ['coffee', 'sausage', 'soft_cheese'],
 ['bottled_water', 'dishes', 'other_vegetables', 'shopping_bags', 'waffles'],
 ['ham', 'rolls/buns', 'whole_milk'],
 ['ice_cream', 'other_vegetables'],
 ['bottled_water', 'other_vegetables'],
 ['bottled_beer', 'prosecco', 'soda', 'white_wine'],
 ['candy', 'herbs'],
 ['bottled_beer',
  'butter',
  'cereals',
  'cream_cheese_',
  'curd',
  'domestic_eggs',
  'frankfurter',
  'frozen_fish',
  'frozen_meals',
  'fruit/vegetable_juice',
  'ham',
  'other_vegetables',
  'pip_fruit',
  'root_vegetables',
  'sliced_cheese',
  'soft_cheese',
  'sugar',
  'tropical_fruit',
  'waffles',
  'whipped/sour_cream',
  'white_bread',
  'whole_milk',
  'yogurt'],
 ['canned_beer', 'rolls/buns'],
 ['cake_bar',
  'cream_cheese_',
  'curd',
  'semi-finished_bread',
  'shopping_bags',
  'specialty_bar',
  'zwieback'],
 ['frankfurter',
  'margarine',
  'shopping_bags',
  'spread_cheese',
  'tropical_fruit',
  'whole_milk'],
 ['other_vegetables'],
 ['dog_food'],
 ['specialty_bar'],
 ['curd', 'detergent', 'liquor_(appetizer)', 'salt', 'shopping_bags'],
 ['frankfurter', 'rolls/buns'],
 ['soda'],
 ['beef',
  'berries',
  'brown_bread',
  'dessert',
  'root_vegetables',
  'spread_cheese',
  'whole_milk'],
 ['canned_beer'],
 ['beef', 'herbs', 'pip_fruit', 'pork', 'spices'],
 ['UHT-milk', 'citrus_fruit', 'frankfurter', 'margarine', 'sugar'],
 ['bottled_beer', 'liquor_(appetizer)', 'sausage'],
 ['canned_beer'],
 ['specialty_chocolate'],
 ['curd', 'rolls/buns'],
 ['canned_beer'],
 ['bottled_water', 'newspapers', 'whole_milk'],
 ['chewing_gum', 'rolls/buns'],
 ['dishes', 'other_vegetables', 'pork', 'root_vegetables', 'whole_milk'],
 ['citrus_fruit', 'pastry'],
 ['pot_plants'],
 ['pastry', 'rolls/buns', 'soda'],
 ['bottled_water',
  'butter',
  'hygiene_articles',
  'make_up_remover',
  'soda',
  'yogurt'],
 ['coffee', 'condensed_milk', 'shopping_bags', 'sugar'],
 ['other_vegetables', 'sausage', 'shopping_bags', 'soda', 'yogurt'],
 ['UHT-milk', 'beverages', 'soda', 'whole_milk'],
 ['beef', 'margarine', 'pork', 'rolls/buns', 'sausage', 'whole_milk'],
 ['beverages'],
 ['beverages', 'specialty_bar'],
 ['bottled_water', 'fruit/vegetable_juice'],
 ['newspapers'],
 ['cleaner', 'female_sanitary_products'],
 ['newspapers', 'sausage', 'shopping_bags', 'soda'],
 ['newspapers'],
 ['beef',
  'beverages',
  'butter_milk',
  'citrus_fruit',
  'cookware',
  'dish_cleaner',
  'hard_cheese',
  'other_vegetables',
  'rolls/buns',
  'sausage',
  'whipped/sour_cream',
  'whole_milk'],
 ['misc._beverages', 'newspapers'],
 ['white_wine'],
 ['canned_beer',
  'rolls/buns',
  'sausage',
  'shopping_bags',
  'sliced_cheese',
  'soda'],
 ['bottled_beer', 'cake_bar', 'curd', 'meat'],
 ['baking_powder',
  'cling_film/bags',
  'frankfurter',
  'meat',
  'oil',
  'onions',
  'tea',
  'tropical_fruit'],
 ['canned_beer', 'ice_cream', 'rolls/buns'],
 ['canned_beer'],
 ['berries',
  'bottled_water',
  'other_vegetables',
  'root_vegetables',
  'shopping_bags',
  'tropical_fruit'],
 ['beverages',
  'bottled_water',
  'brown_bread',
  'butter_milk',
  'citrus_fruit',
  'cream_cheese_',
  'curd',
  'dessert',
  'meat',
  'other_vegetables',
  'rolls/buns',
  'tea'],
 ['bottled_water', 'mustard', 'whole_milk'],
 ['beef',
  'beverages',
  'flower_(seeds)',
  'house_keeping_products',
  'rolls/buns',
  'sausage',
  'sliced_cheese',
  'spices'],
 ['butter',
  'curd',
  'frankfurter',
  'long_life_bakery_product',
  'rolls/buns',
  'root_vegetables',
  'salty_snack',
  'sausage',
  'sliced_cheese'],
 ['butter', 'meat', 'other_vegetables', 'rolls/buns'],
 ['Instant_food_products',
  'beverages',
  'detergent',
  'pickled_vegetables',
  'root_vegetables'],
 ['herbs',
  'other_vegetables',
  'rolls/buns',
  'root_vegetables',
  'sliced_cheese',
  'whole_milk'],
 ['margarine', 'semi-finished_bread', 'whipped/sour_cream', 'whole_milk'],
 ['canned_fish',
  'canned_vegetables',
  'cereals',
  'citrus_fruit',
  'curd',
  'dessert',
  'frozen_dessert',
  'hygiene_articles',
  'napkins',
  'rolls/buns',
  'salt',
  'skin_care',
  'sugar',
  'whipped/sour_cream',
  'whole_milk',
  'yogurt'],
 ['candy',
  'citrus_fruit',
  'curd',
  'margarine',
  'newspapers',
  'pastry',
  'sugar'],
 ['bottled_beer',
  'bottled_water',
  'misc._beverages',
  'napkins',
  'other_vegetables',
  'red/blush_wine',
  'soda',
  'whole_milk'],
 ['citrus_fruit', 'rolls/buns', 'whole_milk'],
 ['hygiene_articles', 'napkins', 'oil', 'sausage'],
 ['beef',
  'bottled_beer',
  'bottled_water',
  'butter',
  'frankfurter',
  'frozen_dessert',
  'grapes',
  'hamburger_meat',
  'potato_products',
  'root_vegetables',
  'whole_milk'],
 ['bottled_water', 'hard_cheese', 'newspapers', 'rolls/buns'],
 ['chocolate', 'cream_cheese_', 'rolls/buns', 'soda'],
 ['beef', 'dishes', 'frozen_vegetables', 'photo/film', 'turkey'],
 ['other_vegetables',
  'pork',
  'rolls/buns',
  'shopping_bags',
  'soda',
  'whipped/sour_cream'],
 ['beverages', 'whole_milk'],
 ['rolls/buns', 'soda'],
 ['bottled_water',
  'curd',
  'hygiene_articles',
  'pip_fruit',
  'rolls/buns',
  'sausage',
  'sliced_cheese',
  'whole_milk',
  'yogurt'],
 ['ice_cream'],
 ['liquor'],
 ['fruit/vegetable_juice', 'other_vegetables', 'pip_fruit'],
 ['other_vegetables', 'root_vegetables', 'yogurt'],
 ['soda'],
 ['soda'],
 ['bottled_water',
  'chocolate',
  'citrus_fruit',
  'newspapers',
  'other_vegetables',
  'rolls/buns',
  'sausage',
  'soda',
  'tropical_fruit',
  'whole_milk',
  'yogurt'],
 ['detergent', 'pet_care', 'root_vegetables', 'whole_milk'],
 ['berries',
  'other_vegetables',
  'pastry',
  'pork',
  'root_vegetables',
  'specialty_bar'],
 ['pork'],
 ['chocolate'],
 ['fruit/vegetable_juice'],
 ['coffee', 'pickled_vegetables'],
 ['bottled_water'],
 ['butter',
  'frankfurter',
  'margarine',
  'rolls/buns',
  'sausage',
  'spices',
  'whipped/sour_cream'],
 ['domestic_eggs',
  'hygiene_articles',
  'napkins',
  'onions',
  'other_vegetables',
  'pip_fruit',
  'soda',
  'soups',
  'sugar',
  'tea',
  'tropical_fruit',
  'whole_milk'],
 ['canned_beer'],
 ['root_vegetables'],
 ['berries', 'citrus_fruit', 'meat', 'root_vegetables', 'soda', 'whole_milk'],
 ['bottled_water',
  'frankfurter',
  'fruit/vegetable_juice',
  'hygiene_articles',
  'rolls/buns'],
 ['margarine', 'rum', 'tropical_fruit'],
 ['butter_milk',
  'flour',
  'herbs',
  'hygiene_articles',
  'root_vegetables',
  'tropical_fruit',
  'whipped/sour_cream',
  'whole_milk'],
 ['baking_powder',
  'brown_bread',
  'citrus_fruit',
  'cream_cheese_',
  'domestic_eggs',
  'margarine',
  'other_vegetables',
  'pip_fruit',
  'root_vegetables',
  'waffles',
  'whole_milk'],
 ['bottled_water',
  'curd',
  'fruit/vegetable_juice',
  'hamburger_meat',
  'margarine',
  'other_vegetables',
  'pastry',
  'rolls/buns',
  'semi-finished_bread',
  'whole_milk',
  'yogurt'],
 ['chicken',
  'dessert',
  'other_vegetables',
  'pasta',
  'pip_fruit',
  'rolls/buns',
  'soda',
  'waffles',
  'whipped/sour_cream',
  'whole_milk',
  'yogurt'],
 ['chicken',
  'citrus_fruit',
  'frozen_fish',
  'rolls/buns',
  'root_vegetables',
  'tropical_fruit',
  'whole_milk'],
 ['citrus_fruit',
  'frankfurter',
  'onions',
  'other_vegetables',
  'rolls/buns',
  'soda',
  'sugar',
  'whole_milk'],
 ['canned_beer'],
 ['pastry', 'pip_fruit', 'salad_dressing', 'turkey'],
 ['bottled_water',
  'brown_bread',
  'curd',
  'domestic_eggs',
  'misc._beverages',
  'mustard',
  'packaged_fruit/vegetables',
  'pickled_vegetables',
  'whole_milk',
  'yogurt'],
 ['pasta'],
 ['citrus_fruit', 'tropical_fruit'],
 ['brown_bread',
  'pot_plants',
  'rolls/buns',
  'sausage',
  'whole_milk',
  'yogurt'],
 ['frozen_meals', 'fruit/vegetable_juice', 'pastry', 'waffles', 'whole_milk'],
 ['canned_beer'],
 ['citrus_fruit', 'sauces', 'sugar'],
 ['liquor_(appetizer)'],
 ['citrus_fruit',
  'other_vegetables',
  'rolls/buns',
  'salty_snack',
  'shopping_bags'],
 ['sausage'],
 ['bottled_water',
  'canned_beer',
  'chicken',
  'napkins',
  'newspapers',
  'oil',
  'other_vegetables',
  'vinegar',
  'whole_milk'],
 ['flour',
  'hamburger_meat',
  'margarine',
  'other_vegetables',
  'root_vegetables',
  'specialty_cheese',
  'whipped/sour_cream',
  'whole_milk',
  'yogurt'],
 ['dessert', 'oil', 'other_vegetables', 'pork', 'sausage', 'soda', 'yogurt'],
 ['abrasive_cleaner',
  'beef',
  'berries',
  'root_vegetables',
  'whipped/sour_cream',
  'whole_milk'],
 ['bottled_water', 'citrus_fruit', 'packaged_fruit/vegetables', 'yogurt'],
 ['UHT-milk', 'coffee'],
 ['candy'],
 ['newspapers'],
 ['beef', 'citrus_fruit', 'other_vegetables', 'yogurt'],
 ['rolls/buns', 'sausage'],
 ['beef',
  'canned_beer',
  'curd',
  'dessert',
  'frankfurter',
  'hygiene_articles',
  'mustard',
  'napkins',
  'pickled_vegetables',
  'rolls/buns',
  'root_vegetables',
  'soft_cheese',
  'yogurt'],
 ['canned_beer'],
 ['bottled_beer'],
 ['chewing_gum', 'chocolate', 'newspapers', 'onions', 'soda'],
 ['candy',
  'cream_cheese_',
  'packaged_fruit/vegetables',
  'tropical_fruit',
  'white_bread'],
 ['bottled_water', 'white_wine'],
 ['beef', 'pasta', 'pastry', 'soap', 'white_bread'],
 ['abrasive_cleaner',
  'candy',
  'chicken',
  'cleaner',
  'root_vegetables',
  'sausage',
  'tropical_fruit',
  'whole_milk',
  'yogurt'],
 ['hair_spray'],
 ['chicken',
  'long_life_bakery_product',
  'shopping_bags',
  'spices',
  'whole_milk'],
 ['brown_bread', 'cat_food', 'citrus_fruit', 'pastry', 'pork', 'sugar'],
 ['ice_cream'],
 ['bottled_beer', 'hard_cheese', 'meat'],
 ['brown_bread', 'instant_coffee', 'other_vegetables', 'yogurt'],
 ['bottled_water', 'cake_bar'],
 ['salty_snack', 'soda', 'tropical_fruit'],
 ['photo/film'],
 ['canned_beer',
  'citrus_fruit',
  'coffee',
  'dishes',
  'sausage',
  'soda',
  'yogurt'],
 ['grapes', 'root_vegetables'],
 ['brown_bread', 'domestic_eggs', 'photo/film'],
 ['canned_beer', 'canned_fish', 'rolls/buns'],
 ['tropical_fruit', 'whole_milk'],
 ['chicken'],
 ['bottled_water', 'brown_bread', 'frankfurter', 'other_vegetables', 'yogurt'],
 ['berries',
  'butter_milk',
  'cream_cheese_',
  'curd',
  'detergent',
  'margarine',
  'misc._beverages',
  'other_vegetables',
  'roll_products_',
  'root_vegetables',
  'specialty_chocolate'],
 ['hygiene_articles', 'margarine'],
 ['rolls/buns', 'shopping_bags', 'soda', 'tropical_fruit', 'yogurt'],
 ['candy',
  'chocolate',
  'ham',
  'hard_cheese',
  'misc._beverages',
  'other_vegetables',
  'rolls/buns',
  'soda',
  'whipped/sour_cream'],
 ['hamburger_meat', 'salty_snack', 'white_bread'],
 ['mayonnaise', 'napkins', 'rolls/buns', 'soda', 'yogurt'],
 ['soda', 'specialty_chocolate'],
 ['yogurt'],
 ['soda'],
 ['bottled_water'],
 ['hamburger_meat', 'meat', 'rubbing_alcohol', 'sausage'],
 ['beverages',
  'citrus_fruit',
  'fruit/vegetable_juice',
  'hard_cheese',
  'pet_care',
  'pip_fruit',
  'soda',
  'waffles'],
 ['shopping_bags'],
 ['newspapers'],
 ['curd',
  'dish_cleaner',
  'frankfurter',
  'frozen_potato_products',
  'other_vegetables',
  'specialty_bar',
  'whole_milk',
  'zwieback'],
 ['canned_beer', 'citrus_fruit', 'sausage', 'whole_milk'],
 ['frankfurter', 'rolls/buns'],
 ['cookware', 'salt', 'salty_snack'],
 ['oil'],
 ['beverages',
  'cake_bar',
  'chewing_gum',
  'cream_cheese_',
  'curd',
  'pastry',
  'rolls/buns',
  'soda'],
 ['butter', 'other_vegetables', 'specialty_chocolate'],
 ['citrus_fruit'],
 ['butter_milk', 'frankfurter', 'whole_milk'],
 ['butter',
  'mayonnaise',
  'processed_cheese',
  'root_vegetables',
  'salty_snack',
  'whole_milk'],
 ['bottled_beer', 'frozen_meals', 'tropical_fruit', 'whole_milk'],
 ['beef', 'hamburger_meat', 'pip_fruit'],
 ['berries', 'cereals', 'shopping_bags', 'waffles', 'whipped/sour_cream'],
 ['canned_beer'],
 ['canned_beer', 'red/blush_wine', 'whipped/sour_cream'],
 ['candy',
  'chocolate_marshmallow',
  'domestic_eggs',
  'margarine',
  'root_vegetables'],
 ['soda', 'whole_milk'],
 ['beef'],
 ['frozen_vegetables'],
 ['bottled_beer', 'rolls/buns'],
 ['hygiene_articles', 'whole_milk'],
 ['whole_milk'],
 ['citrus_fruit', 'curd', 'soft_cheese', 'whole_milk'],
 ['fruit/vegetable_juice', 'pastry'],
 ['brown_bread',
  'butter',
  'frankfurter',
  'pip_fruit',
  'pork',
  'processed_cheese',
  'sausage',
  'white_bread'],
 ['domestic_eggs',
  'root_vegetables',
  'tropical_fruit',
  'whipped/sour_cream',
  'whole_milk'],
 ['frankfurter',
  'napkins',
  'pastry',
  'root_vegetables',
  'sausage',
  'whipped/sour_cream',
  'yogurt'],
 ['berries',
  'cat_food',
  'curd',
  'curd_cheese',
  'detergent',
  'other_vegetables',
  'packaged_fruit/vegetables',
  'root_vegetables',
  'specialty_bar',
  'whole_milk'],
 ['bottled_beer', 'brown_bread', 'coffee', 'pastry', 'rolls/buns'],
 ['coffee',
  'curd',
  'dessert',
  'frozen_vegetables',
  'packaged_fruit/vegetables',
  'root_vegetables',
  'specialty_fat'],
 ['yogurt'],
 ['bottled_water', 'other_vegetables'],
 ['berries', 'white_bread'],
 ['berries', 'coffee'],
 ['bottled_water', 'butter_milk', 'frozen_meals', 'other_vegetables'],
 ['newspapers', 'rolls/buns'],
 ['citrus_fruit',
  'ham',
  'hygiene_articles',
  'pastry',
  'rolls/buns',
  'waffles',
  'whipped/sour_cream',
  'whole_milk'],
 ['frozen_dessert', 'napkins', 'salty_snack', 'whole_milk'],
 ['bottled_water', 'butter_milk', 'rolls/buns', 'tropical_fruit'],
 ['bottled_water'],
 ['butter_milk', 'yogurt'],
 ['newspapers'],
 ['coffee'],
 ['bottled_beer', 'liquor'],
 ['butter',
  'candy',
  'cling_film/bags',
  'frozen_vegetables',
  'hard_cheese',
  'napkins',
  'onions',
  'pasta',
  'specialty_fat',
  'syrup',
  'whipped/sour_cream'],
 ['dog_food',
  'frozen_meals',
  'hamburger_meat',
  'hard_cheese',
  'pasta',
  'salty_snack',
  'shopping_bags'],
 ['cream_cheese_',
  'liver_loaf',
  'other_vegetables',
  'pastry',
  'sausage',
  'shopping_bags',
  'soap'],
 ['hard_cheese', 'napkins', 'pastry'],
 ['condensed_milk', 'rolls/buns', 'sausage', 'tropical_fruit'],
 ['hamburger_meat'],
 ['beverages', 'frozen_dessert', 'onions', 'whole_milk'],
 ['coffee'],
 ['shopping_bags'],
 ['bottled_water', 'pastry', 'rolls/buns', 'shopping_bags', 'soda', 'yogurt'],
 ['soda'],
 ['sliced_cheese'],
 ['coffee', 'sausage', 'whole_milk'],
 ['chocolate', 'yogurt'],
 ['dish_cleaner', 'domestic_eggs', 'hygiene_articles', 'rolls/buns'],
 ['whole_milk'],
 ['meat', 'other_vegetables', 'whipped/sour_cream', 'whole_milk'],
 ['bathroom_cleaner', 'dish_cleaner', 'hygiene_articles', 'napkins'],
 ['other_vegetables', 'red/blush_wine'],
 ['butter_milk',
  'coffee',
  'fruit/vegetable_juice',
  'long_life_bakery_product',
  'rolls/buns',
  'shopping_bags',
  'sliced_cheese',
  'sweet_spreads',
  'whole_milk',
  'yogurt'],
 ['Instant_food_products', 'other_vegetables', 'rolls/buns', 'whole_milk'],
 ['other_vegetables', 'tropical_fruit'],
 ['baking_powder', 'bottled_water', 'chewing_gum', 'salty_snack'],
 ['specialty_bar'],
 ['ice_cream'],
 ['frankfurter', 'yogurt'],
 ['canned_beer'],
 ['bottled_water'],
 ['bottled_beer',
  'bottled_water',
  'margarine',
  'other_vegetables',
  'rolls/buns',
  'whole_milk'],
 ['citrus_fruit',
  'onions',
  'other_vegetables',
  'shopping_bags',
  'tropical_fruit'],
 ['ham',
  'hamburger_meat',
  'newspapers',
  'sausage',
  'soda',
  'softener',
  'whole_milk'],
 ['domestic_eggs', 'napkins', 'rolls/buns', 'specialty_bar'],
 ['citrus_fruit',
  'curd',
  'hygiene_articles',
  'other_vegetables',
  'pork',
  'root_vegetables',
  'tropical_fruit'],
 ['coffee',
  'frozen_vegetables',
  'fruit/vegetable_juice',
  'salty_snack',
  'soda',
  'specialty_cheese'],
 ['citrus_fruit',
  'fruit/vegetable_juice',
  'pip_fruit',
  'pork',
  'sparkling_wine',
  'yogurt'],
 ['beef', 'berries', 'domestic_eggs', 'rolls/buns', 'whipped/sour_cream'],
 ['other_vegetables', 'pet_care'],
 ['chewing_gum', 'chicken', 'dishes', 'rolls/buns', 'sliced_cheese', 'yogurt'],
 ['chewing_gum', 'soda'],
 ['whole_milk'],
 ['rolls/buns'],
 ['bottled_beer'],
 ['bottled_water', 'male_cosmetics', 'pastry', 'root_vegetables'],
 ['pastry'],
 ['berries', 'cake_bar', 'pet_care', 'shopping_bags'],
 ['bottled_water',
  'canned_vegetables',
  'citrus_fruit',
  'root_vegetables',
  'soda',
  'softener',
  'tropical_fruit',
  'yogurt'],
 ['canned_fruit', 'fruit/vegetable_juice', 'oil', 'whole_milk'],
 ['misc._beverages', 'soda'],
 ['bottled_water', 'soda'],
 ['other_vegetables', 'rolls/buns', 'tropical_fruit'],
 ['salty_snack'],
 ['bottled_water', 'canned_beer'],
 ['chocolate'],
 ['UHT-milk', 'citrus_fruit', 'cream_cheese_', 'frozen_vegetables'],
 ['bottled_water', 'canned_beer', 'male_cosmetics'],
 ['bottled_water', 'napkins', 'onions', 'other_vegetables', 'pastry', 'soda'],
 ['cat_food', 'dessert', 'oil', 'soda'],
 ['beef',
  'coffee',
  'dental_care',
  'frozen_potato_products',
  'hygiene_articles',
  'margarine',
  'newspapers',
  'oil',
  'other_vegetables',
  'rolls/buns',
  'whole_milk'],
 ['bottled_beer',
  'bottled_water',
  'brandy',
  'canned_beer',
  'misc._beverages',
  'rolls/buns',
  'zwieback'],
 ['beef',
  'instant_coffee',
  'onions',
  'other_vegetables',
  'root_vegetables',
  'soda',
  'tropical_fruit'],
 ['soda'],
 ['coffee', 'hygiene_articles'],
 ['bottled_water', 'brown_bread', 'rolls/buns'],
 ['beef',
  'frozen_vegetables',
  'hamburger_meat',
  'margarine',
  'other_vegetables',
  'pork',
  'rolls/buns',
  'shopping_bags',
  'whole_milk'],
 ['canned_beer',
  'hygiene_articles',
  'liquor_(appetizer)',
  'napkins',
  'newspapers',
  'soda'],
 ['ham', 'ice_cream', 'other_vegetables', 'sausage', 'white_bread'],
 ['beef', 'other_vegetables', 'rolls/buns', 'root_vegetables', 'sugar'],
 ['bottled_beer', 'bottled_water', 'butter', 'whole_milk'],
 ['house_keeping_products', 'hygiene_articles', 'ice_cream', 'pork'],
 ['berries',
  'fruit/vegetable_juice',
  'ice_cream',
  'packaged_fruit/vegetables',
  'salty_snack',
  'specialty_bar',
  'whole_milk'],
 ['curd',
  'frozen_vegetables',
  'other_vegetables',
  'roll_products_',
  'rolls/buns',
  'sausage',
  'whipped/sour_cream',
  'yogurt'],
 ['bottled_water', 'cling_film/bags', 'misc._beverages'],
 ['bottled_water',
  'frozen_dessert',
  'hard_cheese',
  'other_vegetables',
  'packaged_fruit/vegetables',
  'rice',
  'tropical_fruit',
  'whole_milk'],
 ['bottled_water', 'herbs'],
 ['rolls/buns', 'yogurt'],
 ['Instant_food_products'],
 ['specialty_chocolate'],
 ['coffee'],
 ['bottled_beer', 'liquor'],
 ['beef', 'root_vegetables'],
 ['honey', 'waffles', 'whole_milk'],
 ['frankfurter', 'pastry', 'rolls/buns', 'snack_products', 'specialty_bar'],
 ['curd',
  'frankfurter',
  'frozen_vegetables',
  'hygiene_articles',
  'liver_loaf',
  'photo/film',
  'rolls/buns',
  'root_vegetables',
  'sausage',
  'semi-finished_bread'],
 ['cream_cheese_', 'other_vegetables', 'whole_milk'],
 ['frankfurter',
  'pickled_vegetables',
  'root_vegetables',
  'seasonal_products',
  'soda'],
 ['newspapers', 'rolls/buns', 'whole_milk'],
 ['dental_care', 'frankfurter', 'margarine'],
 ['other_vegetables', 'salty_snack'],
 ['bottled_water', 'shopping_bags'],
 ['butter',
  'hygiene_articles',
  'onions',
  'pastry',
  'pork',
  'rolls/buns',
  'rum',
  'whole_milk'],
 ['bottled_water'],
 ['domestic_eggs',
  'other_vegetables',
  'specialty_cheese',
  'whipped/sour_cream'],
 ['canned_beer', 'curd', 'hamburger_meat', 'pasta', 'whole_milk'],
 ['citrus_fruit', 'hamburger_meat', 'other_vegetables'],
 ['shopping_bags'],
 ['cream_cheese_', 'fruit/vegetable_juice', 'soda', 'whole_milk'],
 ['ice_cream'],
 ['bottled_water', 'pastry'],
 ['baby_cosmetics',
  'butter_milk',
  'chocolate',
  'coffee',
  'cream_cheese_',
  'curd',
  'dessert',
  'ham',
  'long_life_bakery_product',
  'pip_fruit',
  'sliced_cheese',
  'whipped/sour_cream',
  'white_bread',
  'whole_milk'],
 ['frankfurter', 'soda'],
 ['beef',
  'domestic_eggs',
  'flour',
  'misc._beverages',
  'napkins',
  'organic_products',
  'rice',
  'rolls/buns',
  'root_vegetables',
  'sausage',
  'turkey'],
 ['bottled_beer'],
 ['bottled_beer', 'bottled_water', 'napkins'],
 ['bottled_water',
  'frozen_meals',
  'hard_cheese',
  'meat',
  'other_vegetables',
  'soda'],
 ['candy', 'dessert'],
 ['UHT-milk',
  'bottled_water',
  'other_vegetables',
  'packaged_fruit/vegetables'],
 ['beverages', 'rolls/buns', 'soda'],
 ['canned_fish', 'ham', 'mustard'],
 ['specialty_bar'],
 ['brown_bread', 'salty_snack', 'shopping_bags', 'soda'],
 ['coffee', 'cream_cheese_', 'whole_milk'],
 ['pastry', 'red/blush_wine', 'rolls/buns'],
 ['bottled_beer', 'nut_snack'],
 ['bottled_beer', 'pet_care'],
 ['citrus_fruit', 'other_vegetables', 'soda'],
 ['frozen_vegetables', 'hygiene_articles', 'other_vegetables', 'pork'],
 ['other_vegetables', 'shopping_bags'],
 ['detergent', 'white_wine'],
 ['bottled_water', 'dessert', 'whole_milk'],
 ['pip_fruit', 'shopping_bags', 'white_wine'],
 ['bottled_beer', 'soda', 'sugar'],
 ['candy',
  'coffee',
  'fruit/vegetable_juice',
  'pip_fruit',
  'rolls/buns',
  'tropical_fruit'],
 ['bottled_beer',
  'bottled_water',
  'cream_cheese_',
  'frozen_dessert',
  'fruit/vegetable_juice',
  'misc._beverages',
  'root_vegetables',
  'soda',
  'spread_cheese',
  'white_bread'],
 ['misc._beverages', 'soda'],
 ['curd', 'whole_milk'],
 ['bottled_water',
  'male_cosmetics',
  'other_vegetables',
  'tropical_fruit',
  'yogurt'],
 ['brown_bread', 'white_bread'],
 ['brown_bread', 'hygiene_articles', 'sugar'],
 ['bottled_water',
  'candy',
  'coffee',
  'house_keeping_products',
  'red/blush_wine',
  'root_vegetables',
  'shopping_bags',
  'tropical_fruit'],
 ['domestic_eggs'],
 ['coffee', 'detergent', 'hygiene_articles', 'photo/film'],
 ['soda'],
 ['whole_milk'],
 ['bottled_beer'],
 ['beef',
  'berries',
  'cat_food',
  'chocolate',
  'coffee',
  'dish_cleaner',
  'frozen_fish',
  'frozen_potato_products',
  'mayonnaise',
  'mustard',
  'napkins',
  'newspapers',
  'oil',
  'packaged_fruit/vegetables',
  'pork',
  'soda',
  'whole_milk'],
 ['other_vegetables', 'yogurt'],
 ['bottled_water', 'dishes', 'yogurt'],
 ['sparkling_wine'],
 ['bottled_water', 'candy'],
 ['berries',
  'butter_milk',
  'citrus_fruit',
  'fruit/vegetable_juice',
  'hygiene_articles',
  'other_vegetables',
  'sugar'],
 ['hamburger_meat',
  'other_vegetables',
  'rolls/buns',
  'root_vegetables',
  'whole_milk'],
 ['packaged_fruit/vegetables', 'seasonal_products'],
 ['margarine', 'other_vegetables'],
 ['soda'],
 ['bottled_water',
  'frozen_potato_products',
  'fruit/vegetable_juice',
  'margarine',
  'salty_snack',
  'whole_milk',
  'yogurt'],
 ['herbs', 'yogurt'],
 ['citrus_fruit', 'rolls/buns', 'soda', 'spread_cheese'],
 ['misc._beverages'],
 ['female_sanitary_products'],
 ['soda'],
 ['beverages',
  'pasta',
  'shopping_bags',
  'tropical_fruit',
  'white_bread',
  'whole_milk'],
 ['female_sanitary_products', 'soda'],
 ['bottled_water', 'soda', 'waffles', 'white_bread'],
 ['chewing_gum', 'chocolate_marshmallow', 'coffee'],
 ['baking_powder',
  'chocolate_marshmallow',
  'coffee',
  'frozen_vegetables',
  'honey',
  'red/blush_wine',
  'root_vegetables',
  'tropical_fruit',
  'whole_milk'],
 ['butter_milk', 'pip_fruit', 'pork', 'whole_milk'],
 ['bottled_water', 'citrus_fruit'],
 ['frankfurter'],
 ['frankfurter', 'rolls/buns'],
 ['UHT-milk',
  'curd',
  'domestic_eggs',
  'frankfurter',
  'hard_cheese',
  'hygiene_articles',
  'napkins',
  'pip_fruit',
  'rolls/buns',
  'shopping_bags',
  'tropical_fruit'],
 ['other_vegetables'],
 ['fruit/vegetable_juice', 'newspapers', 'yogurt'],
 ['bottled_water',
  'brown_bread',
  'cereals',
  'sausage',
  'soda',
  'whole_milk',
  'yogurt'],
 ['whole_milk'],
 ['bottled_water', 'curd', 'pastry', 'pip_fruit', 'whole_milk'],
 ['whole_milk'],
 ['other_vegetables', 'root_vegetables'],
 ['fruit/vegetable_juice', 'onions'],
 ['specialty_chocolate'],
 ['domestic_eggs', 'hamburger_meat'],
 ['photo/film'],
 ['newspapers', 'rolls/buns', 'snack_products', 'soda'],
 ['canned_beer'],
 ['canned_beer'],
 ['bottled_beer',
  'candles',
  'curd',
  'frozen_meals',
  'frozen_potato_products',
  'kitchen_towels',
  'other_vegetables',
  'soda'],
 ['canned_beer'],
 ['curd', 'rolls/buns', 'spices', 'whipped/sour_cream', 'zwieback'],
 ['butter', 'fruit/vegetable_juice', 'newspapers'],
 ['bottled_water',
  'domestic_eggs',
  'other_vegetables',
  'soda',
  'whole_milk',
  'yogurt'],
 ['whole_milk'],
 ['beef',
  'curd',
  'herbs',
  'sliced_cheese',
  'tropical_fruit',
  'whipped/sour_cream',
  'whole_milk',
  'yogurt'],
 ['rolls/buns', 'sausage'],
 ['soda'],
 ['fruit/vegetable_juice', 'long_life_bakery_product'],
 ['coffee',
  'detergent',
  'long_life_bakery_product',
  'rolls/buns',
  'shopping_bags'],
 ['bottled_water', 'candy', 'pip_fruit', 'whole_milk'],
 ['bottled_beer',
  'chewing_gum',
  'frozen_vegetables',
  'liquor_(appetizer)',
  'napkins',
  'newspapers'],
 ['beverages'],
 ['domestic_eggs',
  'hamburger_meat',
  'hygiene_articles',
  'margarine',
  'oil',
  'other_vegetables',
  'roll_products_',
  'root_vegetables'],
 ['fruit/vegetable_juice',
  'other_vegetables',
  'root_vegetables',
  'white_wine',
  'whole_milk',
  'yogurt'],
 ['canned_beer'],
 ['bottled_beer', 'frozen_vegetables'],
 ['canned_beer'],
 ['newspapers'],
 ['rolls/buns'],
 ['UHT-milk', 'hamburger_meat', 'salty_snack'],
 ['curd', 'pip_fruit', 'rum', 'whole_milk'],
 ['canned_beer'],
 ['domestic_eggs',
  'frozen_vegetables',
  'grapes',
  'root_vegetables',
  'white_wine'],
 ['butter',
  'packaged_fruit/vegetables',
  'rolls/buns',
  'root_vegetables',
  'whipped/sour_cream'],
 ['canned_beer',
  'citrus_fruit',
  'frozen_vegetables',
  'rolls/buns',
  'salty_snack'],
 ['cling_film/bags', 'pot_plants'],
 ['baking_powder',
  'bottled_beer',
  'frankfurter',
  'margarine',
  'rolls/buns',
  'whole_milk'],
 ['red/blush_wine', 'whole_milk'],
 ['baking_powder',
  'cereals',
  'curd',
  'domestic_eggs',
  'frozen_dessert',
  'frozen_meals',
  'fruit/vegetable_juice',
  'hard_cheese',
  'pork',
  'soap',
  'tropical_fruit',
  'whole_milk',
  'yogurt'],
 ['chicken', 'pastry'],
 ['dish_cleaner', 'dishes', 'sausage'],
 ['specialty_bar'],
 ['pastry', 'specialty_bar', 'whipped/sour_cream'],
 ['brown_bread', 'root_vegetables'],
 ['rolls/buns', 'soda'],
 ['bottled_beer', 'other_vegetables', 'red/blush_wine'],
 ['berries',
  'bottled_water',
  'butter',
  'citrus_fruit',
  'hygiene_articles',
  'napkins',
  'other_vegetables',
  'root_vegetables',
  'rubbing_alcohol',
  'tropical_fruit',
  'whole_milk'],
 ['brown_bread', 'pastry', 'processed_cheese', 'soda', 'whole_milk'],
 ['candy',
  'frankfurter',
  'pastry',
  'rolls/buns',
  'root_vegetables',
  'sausage',
  'tropical_fruit',
  'whole_milk',
  'yogurt'],
 ['coffee', 'long_life_bakery_product'],
 ['ham', 'rolls/buns', 'white_wine'],
 ['canned_beer'],
 ['canned_beer'],
 ['canned_beer'],
 ['canned_fish', 'pip_fruit', 'whole_milk'],
 ['bottled_water',
  'curd',
  'other_vegetables',
  'pip_fruit',
  'pork',
  'soda',
  'sugar',
  'white_bread',
  'whole_milk'],
 ['soap'],
 ['bottled_water', 'butter', 'frozen_meals', 'pasta', 'pip_fruit'],
 ['beef', 'citrus_fruit', 'hamburger_meat', 'mustard', 'soap', 'whole_milk'],
 ['bottled_beer',
  'chocolate',
  'meat',
  'newspapers',
  'other_vegetables',
  'rolls/buns',
  'sausage',
  'soda',
  'whole_milk',
  'yogurt'],
 ['frozen_chicken'],
 ['soda'],
 ['bottled_beer',
  'bottled_water',
  'brown_bread',
  'curd',
  'rolls/buns',
  'seasonal_products',
  'tropical_fruit',
  'yogurt'],
 ['other_vegetables'],
 ['beef',
  'citrus_fruit',
  'curd',
  'detergent',
  'margarine',
  'newspapers',
  'oil',
  'rolls/buns',
  'specialty_bar'],
 ['beef',
  'citrus_fruit',
  'meat',
  'other_vegetables',
  'pickled_vegetables',
  'pork',
  'root_vegetables',
  'whole_milk'],
 ['butter',
  'hamburger_meat',
  'meat',
  'newspapers',
  'packaged_fruit/vegetables',
  'root_vegetables',
  'whole_milk'],
 ['bottled_water',
  'long_life_bakery_product',
  'newspapers',
  'red/blush_wine',
  'soda'],
 ['rolls/buns'],
 ['canned_beer', 'pastry'],
 ['pastry', 'pork', 'sauces', 'whole_milk'],
 ['light_bulbs',
  'newspapers',
  'pastry',
  'pip_fruit',
  'sliced_cheese',
  'white_wine'],
 ['UHT-milk',
  'beef',
  'bottled_water',
  'citrus_fruit',
  'frozen_vegetables',
  'rolls/buns',
  'skin_care',
  'tropical_fruit',
  'yogurt'],
 ['beef',
  'berries',
  'brown_bread',
  'citrus_fruit',
  'coffee',
  'kitchen_towels',
  'sugar'],
 ['rolls/buns', 'spices'],
 ['butter',
  'canned_vegetables',
  'citrus_fruit',
  'curd',
  'frozen_vegetables',
  'herbs',
  'misc._beverages',
  'tropical_fruit',
  'whipped/sour_cream',
  'whole_milk'],
 ['beef',
  'coffee',
  'flour',
  'frozen_dessert',
  'herbs',
  'meat',
  'oil',
  'pot_plants',
  'rolls/buns',
  'semi-finished_bread',
  'whole_milk'],
 ['beverages', 'bottled_water', 'pastry'],
 ['beef', 'citrus_fruit', 'other_vegetables', 'rolls/buns'],
 ['hair_spray', 'ham', 'margarine', 'white_bread', 'whole_milk'],
 ['Instant_food_products',
  'bottled_beer',
  'canned_fish',
  'coffee',
  'hamburger_meat',
  'hygiene_articles',
  'ketchup',
  'newspapers',
  'oil',
  'soups',
  'whole_milk'],
 ['beef',
  'bottled_water',
  'butter_milk',
  'citrus_fruit',
  'fruit/vegetable_juice',
  'margarine',
  'other_vegetables',
  'processed_cheese',
  'rolls/buns',
  'sliced_cheese'],
 ['beef',
  'citrus_fruit',
  'domestic_eggs',
  'fruit/vegetable_juice',
  'pastry',
  'roll_products_',
  'rolls/buns',
  'tea',
  'whole_milk'],
 ['detergent', 'root_vegetables', 'whole_milk'],
 ['candy',
  'citrus_fruit',
  'cling_film/bags',
  'frozen_vegetables',
  'fruit/vegetable_juice',
  'grapes',
  'liquor',
  'liquor_(appetizer)',
  'other_vegetables',
  'pickled_vegetables',
  'rum',
  'tropical_fruit'],
 ['bottled_water', 'yogurt'],
 ['brown_bread',
  'canned_fish',
  'long_life_bakery_product',
  'other_vegetables',
  'root_vegetables',
  'tropical_fruit',
  'whipped/sour_cream'],
 ['frankfurter', 'newspapers', 'root_vegetables'],
 ['abrasive_cleaner',
  'beef',
  'brown_bread',
  'other_vegetables',
  'pastry',
  'salty_snack',
  'shopping_bags',
  'whole_milk'],
 ['shopping_bags'],
 ['canned_beer'],
 ['canned_beer', 'rolls/buns'],
 ['bottled_water',
  'candy',
  'chocolate',
  'meat_spreads',
  'misc._beverages',
  'other_vegetables',
  'rolls/buns',
  'soda',
  'waffles'],
 ['bottled_water',
  'hamburger_meat',
  'other_vegetables',
  'rolls/buns',
  'yogurt'],
 ['Instant_food_products',
  'bottled_water',
  'canned_fish',
  'citrus_fruit',
  'fruit/vegetable_juice',
  'hamburger_meat',
  'napkins',
  'rolls/buns',
  'root_vegetables',
  'soda'],
 ['chewing_gum',
  'domestic_eggs',
  'frankfurter',
  'sausage',
  'shopping_bags',
  'soda'],
 ['bottled_beer'],
 ['domestic_eggs', 'pastry', 'rolls/buns', 'tropical_fruit'],
 ['soda'],
 ['canned_beer',
  'frankfurter',
  'onions',
  'other_vegetables',
  'root_vegetables',
  'white_bread'],
 ['canned_beer',
  'chicken',
  'cling_film/bags',
  'dish_cleaner',
  'hamburger_meat',
  'herbs',
  'napkins',
  'soda',
  'soups',
  'whipped/sour_cream'],
 ['coffee', 'soda'],
 ['whole_milk'],
 ['margarine'],
 ['other_vegetables', 'tropical_fruit'],
 ['meat', 'other_vegetables'],
 ['bottled_water', 'canned_beer', 'cream_cheese_'],
 ['newspapers'],
 ['newspapers', 'pastry', 'rolls/buns'],
 ['citrus_fruit',
  'curd',
  'fruit/vegetable_juice',
  'long_life_bakery_product',
  'other_vegetables',
  'potato_products',
  'whole_milk',
  'yogurt'],
 ['detergent', 'rolls/buns', 'whole_milk'],
 ['UHT-milk',
  'butter_milk',
  'citrus_fruit',
  'female_sanitary_products',
  'frankfurter',
  'rolls/buns',
  'shopping_bags'],
 ['butter', 'ham', 'other_vegetables', 'soda', 'sugar', 'whipped/sour_cream'],
 ['bottled_beer', 'citrus_fruit', 'frankfurter', 'salty_snack'],
 ['coffee', 'curd', 'domestic_eggs', 'onions', 'sausage', 'yogurt'],
 ['domestic_eggs'],
 ['domestic_eggs', 'rolls/buns', 'soda', 'whole_milk'],
 ['bottled_beer', 'newspapers', 'rolls/buns'],
 ['chocolate_marshmallow', 'hard_cheese', 'whole_milk'],
 ['other_vegetables', 'rolls/buns', 'root_vegetables', 'sausage', 'soda'],
 ['beverages', 'butter_milk', 'curd', 'yogurt'],
 ['bottled_water'],
 ['beef'],
 ['chocolate_marshmallow',
  'coffee',
  'frankfurter',
  'hamburger_meat',
  'mustard',
  'newspapers',
  'potato_products',
  'rolls/buns',
  'soap',
  'waffles',
  'whole_milk'],
 ['butter', 'chicken', 'newspapers'],
 ['candles',
  'coffee',
  'meat',
  'pastry',
  'pip_fruit',
  'pot_plants',
  'sausage',
  'sugar',
  'tropical_fruit'],
 ['beverages', 'pork', 'whipped/sour_cream', 'whole_milk'],
 ['coffee', 'pastry', 'yogurt'],
 ['cat_food',
  'detergent',
  'dishes',
  'margarine',
  'shopping_bags',
  'sliced_cheese',
  'whole_milk'],
 ['frankfurter',
  'fruit/vegetable_juice',
  'ham',
  'napkins',
  'pastry',
  'rolls/buns',
  'soda',
  'sugar',
  'vinegar',
  'whole_milk',
  'yogurt'],
 ['beef', 'brown_bread', 'newspapers', 'specialty_chocolate', 'whole_milk'],
 ['butter_milk',
  'cream_cheese_',
  'other_vegetables',
  'pip_fruit',
  'rolls/buns'],
 ['chocolate', 'coffee', 'rolls/buns', 'sausage', 'whole_milk'],
 ['coffee', 'pastry'],
 ['beef', 'chicken', 'specialty_chocolate'],
 ['chocolate',
  'frozen_dessert',
  'frozen_fish',
  'frozen_vegetables',
  'other_vegetables',
  'root_vegetables',
  'sliced_cheese',
  'whole_milk'],
 ['frozen_meals', 'rolls/buns', 'whole_milk'],
 ['detergent'],
 ['canned_fish', 'rolls/buns'],
 ['house_keeping_products'],
 ['cleaner', 'jam', 'salt', 'sparkling_wine', 'yogurt'],
 ['curd', 'rolls/buns', 'sliced_cheese', 'soda', 'tropical_fruit'],
 ['tropical_fruit'],
 ['UHT-milk', 'artif._sweetener', 'curd', 'dental_care'],
 ['beef', 'berries', 'onions', 'rolls/buns'],
 ['bottled_water',
  'brown_bread',
  'margarine',
  'napkins',
  'newspapers',
  'pasta',
  'whole_milk'],
 ['UHT-milk', 'bottled_water', 'canned_beer', 'pork', 'soda'],
 ['cleaner',
  'curd',
  'curd_cheese',
  'hygiene_articles',
  'margarine',
  'other_vegetables',
  'yogurt'],
 ['canned_beer',
  'fruit/vegetable_juice',
  'long_life_bakery_product',
  'rolls/buns',
  'shopping_bags',
  'soda',
  'white_wine'],
 ['frankfurter', 'pip_fruit', 'roll_products_', 'rolls/buns', 'whole_milk'],
 ['hygiene_articles', 'newspapers', 'shopping_bags', 'yogurt'],
 ['cat_food', 'coffee', 'curd', 'sliced_cheese', 'whole_milk'],
 ['bottled_water', 'candy'],
 ['beef', 'butter', 'frankfurter'],
 ['rolls/buns', 'shopping_bags', 'snack_products', 'soda'],
 ['bottled_water', 'hygiene_articles', 'pastry', 'whole_milk'],
 ['rolls/buns'],
 ['brown_bread',
  'chicken',
  'onions',
  'other_vegetables',
  'red/blush_wine',
  'white_wine',
  'whole_milk'],
 ['butter', 'dishes', 'onions', 'tropical_fruit', 'whole_milk'],
 ['brown_bread',
  'hygiene_articles',
  'oil',
  'other_vegetables',
  'sausage',
  'shopping_bags',
  'turkey',
  'yogurt'],
 ['candy',
  'curd',
  'hard_cheese',
  'newspapers',
  'other_vegetables',
  'sausage',
  'soda',
  'whole_milk'],
 ['citrus_fruit',
  'frankfurter',
  'instant_coffee',
  'margarine',
  'pastry',
  'ready_soups',
  'shopping_bags'],
 ['UHT-milk',
  'decalcifier',
  'frozen_dessert',
  'fruit/vegetable_juice',
  'newspapers'],
 ['newspapers', 'rolls/buns'],
 ['canned_beer'],
 ['specialty_bar', 'yogurt'],
 ['specialty_bar', 'whipped/sour_cream'],
 ['canned_beer', 'rolls/buns'],
 ['rolls/buns'],
 ['beverages', 'rolls/buns'],
 ['rolls/buns'],
 ['rolls/buns', 'shopping_bags'],
 ['bottled_beer'],
 ['bottled_water',
  'citrus_fruit',
  'curd',
  'oil',
  'rolls/buns',
  'sliced_cheese',
  'yogurt'],
 ['bottled_water', 'soda'],
 ['pastry'],
 ['candles', 'coffee', 'domestic_eggs', 'pastry', 'rolls/buns'],
 ['beef', 'margarine', 'pip_fruit', 'rolls/buns', 'root_vegetables'],
 ['bottled_water', 'newspapers', 'rolls/buns', 'spread_cheese'],
 ['rolls/buns', 'soda', 'spread_cheese', 'tropical_fruit'],
 ['candles', 'canned_beer', 'packaged_fruit/vegetables'],
 ['bottled_beer',
  'napkins',
  'salty_snack',
  'white_wine',
  'whole_milk',
  'yogurt'],
 ['beef',
  'butter',
  'domestic_eggs',
  'meat',
  'other_vegetables',
  'rolls/buns',
  'whole_milk'],
 ['bottled_beer',
  'detergent',
  'dishes',
  'liquor_(appetizer)',
  'onions',
  'whole_milk'],
 ['UHT-milk',
  'bottled_water',
  'brown_bread',
  'butter_milk',
  'frankfurter',
  'grapes',
  'margarine',
  'organic_products',
  'other_vegetables',
  'soda'],
 ['beef', 'bottled_beer', 'rolls/buns'],
 ['beef'],
 ['bottled_beer', 'liquor_(appetizer)', 'sausage'],
 ['chicken', 'herbs', 'hygiene_articles', 'onions'],
 ['canned_beer'],
 ['bottled_beer',
  'other_vegetables',
  'root_vegetables',
  'sausage',
  'seasonal_products',
  'whole_milk'],
 ['curd', 'tropical_fruit', 'whipped/sour_cream', 'whole_milk', 'yogurt'],
 ['abrasive_cleaner',
  'flower_(seeds)',
  'frankfurter',
  'newspapers',
  'rolls/buns',
  'soda'],
 ['sausage', 'semi-finished_bread', 'tropical_fruit'],
 ['beef', 'root_vegetables', 'tropical_fruit', 'yogurt'],
 ['flour', 'pastry', 'rum', 'tropical_fruit'],
 ['yogurt'],
 ['frankfurter', 'mustard', 'rolls/buns'],
 ['bottled_beer'],
 ['grapes', 'soda'],
 ['beverages', 'rolls/buns'],
 ['bottled_beer', 'curd', 'pot_plants'],
 ['flower_(seeds)', 'ice_cream', 'sugar'],
 ['canned_beer', 'rolls/buns', 'sausage', 'shopping_bags', 'soda'],
 ['other_vegetables'],
 ['beverages', 'bottled_water', 'dessert'],
 ['decalcifier'],
 ['canned_beer'],
 ['coffee'],
 ['berries', 'other_vegetables', 'whipped/sour_cream', 'whole_milk'],
 ['bottled_beer',
  'newspapers',
  'pork',
  'rolls/buns',
  'semi-finished_bread',
  'tropical_fruit'],
 ['baking_powder',
  'butter_milk',
  'chicken',
  'citrus_fruit',
  'cream_cheese_',
  'domestic_eggs',
  'frankfurter',
  'frozen_dessert',
  'other_vegetables',
  'pork',
  'rolls/buns',
  'sugar',
  'whipped/sour_cream',
  'whole_milk'],
 ['beef',
  'bottled_beer',
  'bottled_water',
  'domestic_eggs',
  'hygiene_articles',
  'pork',
  'whole_milk'],
 ['bottled_water',
  'cat_food',
  'citrus_fruit',
  'frankfurter',
  'onions',
  'other_vegetables',
  'packaged_fruit/vegetables',
  'pork',
  'root_vegetables'],
 ['brandy', 'frozen_dessert'],
 ['chicken',
  'condensed_milk',
  'frozen_vegetables',
  'fruit/vegetable_juice',
  'other_vegetables',
  'packaged_fruit/vegetables'],
 ['oil', 'vinegar'],
 ['rolls/buns', 'soda', 'specialty_bar'],
 ['whole_milk'],
 ['pork', 'root_vegetables', 'whipped/sour_cream', 'whole_milk'],
 ['newspapers', 'rolls/buns'],
 ['Instant_food_products', 'dishes', 'grapes', 'other_vegetables', 'zwieback'],
 ['baking_powder',
  'citrus_fruit',
  'cream_cheese_',
  'frankfurter',
  'napkins',
  'rolls/buns',
  'seasonal_products',
  'whipped/sour_cream'],
 ['bottled_beer',
  'finished_products',
  'frozen_vegetables',
  'ice_cream',
  'packaged_fruit/vegetables',
  'root_vegetables',
  'soda',
  'specialty_cheese',
  'yogurt'],
 ['flour', 'onions', 'other_vegetables'],
 ['rolls/buns', 'tropical_fruit', 'whole_milk'],
 ['chocolate',
  'chocolate_marshmallow',
  'cream_cheese_',
  'other_vegetables',
  'tea'],
 ['beef', 'ham', 'other_vegetables', 'pot_plants', 'turkey', 'whole_milk'],
 ['bottled_beer', 'margarine', 'other_vegetables', 'whole_milk'],
 ['curd'],
 ['beef', 'other_vegetables', 'sausage'],
 ['canned_beer', 'chewing_gum', 'liquor_(appetizer)'],
 ['berries',
  'cake_bar',
  'candy',
  'chicken',
  'citrus_fruit',
  'curd',
  'frozen_vegetables',
  'ham',
  'liquor_(appetizer)',
  'margarine',
  'onions',
  'rolls/buns',
  'seasonal_products',
  'skin_care',
  'soda',
  'whole_milk',
  'yogurt'],
 ['UHT-milk',
  'bottled_water',
  'dessert',
  'long_life_bakery_product',
  'margarine',
  'packaged_fruit/vegetables',
  'whole_milk',
  'yogurt'],
 ['meat', 'rolls/buns', 'soda', 'specialty_bar'],
 ['dessert', 'whole_milk'],
 ['canned_beer'],
 ['UHT-milk',
  'chicken',
  'coffee',
  'house_keeping_products',
  'long_life_bakery_product',
  'rolls/buns'],
 ['newspapers', 'red/blush_wine', 'rolls/buns'],
 ['bottled_water', 'pet_care'],
 ['other_vegetables', 'root_vegetables', 'shopping_bags', 'soda'],
 ['pastry'],
 ['bottled_water',
  'brown_bread',
  'domestic_eggs',
  'flower_(seeds)',
  'frankfurter',
  'hamburger_meat',
  'margarine',
  'rolls/buns',
  'whole_milk'],
 ['chicken', 'grapes', 'mayonnaise', 'whipped/sour_cream', 'whole_milk'],
 ['frozen_dessert', 'semi-finished_bread'],
 ['bottled_water',
  'candy',
  'canned_fruit',
  'citrus_fruit',
  'female_sanitary_products',
  'grapes',
  'margarine',
  'misc._beverages',
  'rolls/buns',
  'shopping_bags',
  'soda',
  'tropical_fruit',
  'yogurt'],
 ['beef',
  'berries',
  'bottled_water',
  'butter',
  'cat_food',
  'newspapers',
  'pork',
  'rolls/buns',
  'root_vegetables',
  'sausage',
  'whole_milk'],
 ['baking_powder',
  'detergent',
  'frozen_vegetables',
  'onions',
  'other_vegetables',
  'packaged_fruit/vegetables',
  'pasta',
  'rolls/buns',
  'root_vegetables',
  'soda',
  'soups',
  'whipped/sour_cream',
  'whole_milk'],
 ['rolls/buns', 'root_vegetables', 'whole_milk', 'yogurt'],
 ['bottled_beer'],
 ['canned_beer', 'frankfurter'],
 ['butter', 'coffee', 'root_vegetables', 'whole_milk'],
 ['UHT-milk',
  'berries',
  'bottled_water',
  'hygiene_articles',
  'newspapers',
  'other_vegetables',
  'soda',
  'whipped/sour_cream'],
 ['hamburger_meat'],
 ['fruit/vegetable_juice',
  'long_life_bakery_product',
  'margarine',
  'newspapers',
  'rolls/buns',
  'semi-finished_bread',
  'tropical_fruit',
  'whole_milk'],
 ['beverages', 'frankfurter', 'frozen_meals', 'pork', 'waffles'],
 ['frankfurter', 'frozen_fish', 'margarine', 'sausage', 'specialty_bar'],
 ['newspapers', 'soda'],
 ['ice_cream'],
 ['beef',
  'brown_bread',
  'coffee',
  'frozen_vegetables',
  'pastry',
  'whole_milk'],
 ['bottled_water', 'newspapers', 'pastry', 'photo/film', 'whole_milk'],
 ['butter',
  'curd',
  'fish',
  'flour',
  'pork',
  'sugar',
  'whipped/sour_cream',
  'whole_milk',
  'yogurt'],
 ['chewing_gum', 'whole_milk'],
 ['bottled_beer'],
 ['UHT-milk', 'brown_bread', 'grapes', 'margarine', 'pork'],
 ['pot_plants', 'root_vegetables'],
 ['canned_beer'],
 ['bottled_beer',
  'bottled_water',
  'butter',
  'citrus_fruit',
  'mustard',
  'oil',
  'root_vegetables',
  'whipped/sour_cream',
  'whole_milk'],
 ['coffee',
  'female_sanitary_products',
  'herbs',
  'hygiene_articles',
  'other_vegetables',
  'pip_fruit',
  'shopping_bags',
  'whole_milk'],
 ['cream_cheese_', 'dessert', 'rice', 'root_vegetables', 'yogurt'],
 ['curd', 'newspapers', 'organic_products', 'rolls/buns', 'tropical_fruit'],
 ['beef',
  'butter',
  'candles',
  'coffee',
  'domestic_eggs',
  'hard_cheese',
  'other_vegetables',
  'pasta',
  'root_vegetables',
  'soft_cheese',
  'whole_milk'],
 ['butter', 'chicken', 'pork', 'white_bread', 'whole_milk'],
 ['candles',
  'citrus_fruit',
  'grapes',
  'margarine',
  'newspapers',
  'oil',
  'pastry',
  'rolls/buns',
  'whole_milk'],
 ['beef',
  'coffee',
  'frozen_meals',
  'fruit/vegetable_juice',
  'margarine',
  'meat',
  'other_vegetables',
  'pip_fruit',
  'pot_plants',
  'soft_cheese',
  'tropical_fruit',
  'whipped/sour_cream'],
 ['cream_cheese_', 'rolls/buns', 'spread_cheese'],
 ['bottled_beer',
  'bottled_water',
  'citrus_fruit',
  'herbs',
  'pot_plants',
  'whole_milk'],
 ['specialty_bar'],
 ['beverages',
  'chocolate',
  'margarine',
  'meat',
  'napkins',
  'newspapers',
  'other_vegetables',
  'rolls/buns',
  'whole_milk'],
 ['citrus_fruit', 'pip_fruit', 'tropical_fruit'],
 ['beef',
  'frankfurter',
  'frozen_vegetables',
  'packaged_fruit/vegetables',
  'root_vegetables',
  'tropical_fruit',
  'whole_milk'],
 ['citrus_fruit', 'whole_milk'],
 ['bottled_beer',
  'curd',
  'other_vegetables',
  'root_vegetables',
  'specialty_chocolate',
  'turkey'],
 ['canned_beer',
  'citrus_fruit',
  'curd',
  'dog_food',
  'mustard',
  'onions',
  'pasta',
  'rolls/buns',
  'whole_milk',
  'yogurt'],
 ['domestic_eggs', 'sausage'],
 ['newspapers'],
 ['whole_milk', 'yogurt'],
 ['yogurt'],
 ['yogurt'],
 ['bottled_water'],
 ['berries', 'domestic_eggs', 'whipped/sour_cream', 'whole_milk'],
 ['packaged_fruit/vegetables', 'pastry', 'rolls/buns', 'whole_milk'],
 ['frankfurter', 'soda'],
 ['jam',
  'nuts/prunes',
  'pot_plants',
  'semi-finished_bread',
  'shopping_bags',
  'soda',
  'whole_milk'],
 ['butter',
  'citrus_fruit',
  'coffee',
  'dishes',
  'flour',
  'other_vegetables',
  'packaged_fruit/vegetables',
  'soda',
  'sparkling_wine',
  'sugar',
  'whipped/sour_cream',
  'whole_milk'],
 ['beef',
  'citrus_fruit',
  'curd',
  'fruit/vegetable_juice',
  'hard_cheese',
  'onions',
  'rolls/buns',
  'root_vegetables'],
 ['canned_beer',
  'coffee',
  'frozen_vegetables',
  'napkins',
  'whole_milk',
  'yogurt'],
 ['other_vegetables', 'whipped/sour_cream'],
 ['beef', 'other_vegetables'],
 ['berries',
  'coffee',
  'dessert',
  'fish',
  'other_vegetables',
  'red/blush_wine',
  'spread_cheese',
  'white_wine',
  'whole_milk',
  'yogurt'],
 ['curd',
  'domestic_eggs',
  'frozen_vegetables',
  'instant_coffee',
  'newspapers',
  'other_vegetables',
  'sugar',
  'whole_milk'],
 ['berries',
  'butter',
  'hard_cheese',
  'napkins',
  'root_vegetables',
  'sliced_cheese',
  'specialty_chocolate',
  'tropical_fruit',
  'whipped/sour_cream',
  'whole_milk',
  'yogurt'],
 ['coffee'],
 ['artif._sweetener',
  'bottled_water',
  'frozen_fish',
  'hygiene_articles',
  'newspapers',
  'other_vegetables',
  'pork',
  'ready_soups',
  'rolls/buns',
  'sausage',
  'semi-finished_bread'],
 ['beverages',
  'cream_cheese_',
  'dishes',
  'meat',
  'root_vegetables',
  'waffles',
  'whipped/sour_cream'],
 ['abrasive_cleaner',
  'butter',
  'chicken',
  'long_life_bakery_product',
  'margarine',
  'other_vegetables',
  'packaged_fruit/vegetables',
  'pip_fruit',
  'rolls/buns',
  'root_vegetables',
  'rum',
  'sugar',
  'tropical_fruit'],
 ['berries',
  'fruit/vegetable_juice',
  'margarine',
  'organic_products',
  'shopping_bags',
  'whipped/sour_cream',
  'whole_milk'],
 ['frozen_meals', 'misc._beverages'],
 ['whipped/sour_cream'],
 ['beef', 'bottled_beer', 'chocolate', 'root_vegetables', 'shopping_bags'],
 ['UHT-milk',
  'bottled_beer',
  'bottled_water',
  'chicken',
  'domestic_eggs',
  'fruit/vegetable_juice',
  'other_vegetables',
  'pork',
  'rolls/buns',
  'soda',
  'whipped/sour_cream',
  'whole_milk'],
 ['Instant_food_products',
  'brown_bread',
  'chicken',
  'frozen_potato_products',
  'fruit/vegetable_juice',
  'hamburger_meat',
  'nuts/prunes',
  'other_vegetables',
  'pip_fruit',
  'pork',
  'root_vegetables',
  'shopping_bags',
  'soda',
  'spread_cheese',
  'whole_milk'],
 ['beef',
  'bottled_beer',
  'bottled_water',
  'brown_bread',
  'hard_cheese',
  'herbs',
  'other_vegetables',
  'rolls/buns',
  'root_vegetables',
  'salty_snack',
  'shopping_bags',
  'tropical_fruit',
  'whole_milk',
  'yogurt'],
 ['packaged_fruit/vegetables', 'pickled_vegetables'],
 ['sugar'],
 ['beef',
  'dessert',
  'frankfurter',
  'ice_cream',
  'packaged_fruit/vegetables',
  'rolls/buns',
  'root_vegetables',
  'sausage',
  'sliced_cheese',
  'soda',
  'whole_milk',
  'yogurt'],
 ['berries', 'frozen_vegetables', 'instant_coffee', 'pet_care'],
 ['bottled_water', 'chewing_gum', 'napkins', 'soda'],
 ['abrasive_cleaner',
  'berries',
  'beverages',
  'chicken',
  'citrus_fruit',
  'curd',
  'root_vegetables',
  'sausage'],
 ['UHT-milk',
  'dishes',
  'domestic_eggs',
  'fruit/vegetable_juice',
  'newspapers',
  'soda',
  'whole_milk'],
 ['ice_cream', 'rolls/buns'],
 ['citrus_fruit', 'frankfurter', 'rolls/buns', 'tropical_fruit'],
 ['brandy',
  'brown_bread',
  'dog_food',
  'root_vegetables',
  'shopping_bags',
  'sweet_spreads',
  'white_bread',
  'whole_milk'],
 ['rolls/buns', 'sausage', 'specialty_chocolate'],
 ['baking_powder',
  'berries',
  'citrus_fruit',
  'ham',
  'packaged_fruit/vegetables',
  'pastry',
  'sausage',
  'sliced_cheese',
  'sugar',
  'tropical_fruit',
  'whipped/sour_cream',
  'whole_milk'],
 ['beef', 'cream_cheese_', 'root_vegetables', 'whole_milk'],
 ['fruit/vegetable_juice'],
 ['hygiene_articles', 'sugar'],
 ['berries', 'whipped/sour_cream'],
 ['beverages', 'coffee', 'yogurt'],
 ['beef', 'pork'],
 ['bottled_beer', 'shopping_bags'],
 ['butter_milk', 'coffee', 'curd', 'sliced_cheese', 'yogurt'],
 ['Instant_food_products', 'beef', 'canned_beer'],
 ['berries',
  'beverages',
  'chocolate',
  'flour',
  'newspapers',
  'oil',
  'pork',
  'soda',
  'whipped/sour_cream'],
 ['white_bread'],
 ['fruit/vegetable_juice',
  'grapes',
  'processed_cheese',
  'rolls/buns',
  'white_bread',
  'whole_milk'],
 ['flower_(seeds)', 'potato_products'],
 ['bottled_water',
  'coffee',
  'dishes',
  'onions',
  'rolls/buns',
  'root_vegetables',
  'yogurt'],
 ['UHT-milk',
  'bathroom_cleaner',
  'canned_beer',
  'chicken',
  'hamburger_meat',
  'newspapers',
  'soda'],
 ['chicken', 'other_vegetables', 'salt'],
 ['coffee', 'cream_cheese_', 'fish'],
 ['canned_beer'],
 ['brown_bread',
  'frozen_meals',
  'napkins',
  'other_vegetables',
  'rolls/buns',
  'whole_milk'],
 ['bottled_beer',
  'brown_bread',
  'chicken',
  'frozen_vegetables',
  'newspapers',
  'pork',
  'red/blush_wine',
  'vinegar',
  'whole_milk'],
 ['misc._beverages', 'other_vegetables'],
 ['tropical_fruit', 'whole_milk'],
 ['cake_bar', 'newspapers', 'whole_milk'],
 ['beef', 'berries', 'hamburger_meat', 'hygiene_articles', 'pastry'],
 ['grapes', 'rolls/buns', 'salty_snack', 'sausage', 'soda'],
 ['chocolate', 'rolls/buns', 'whole_milk'],
 ['rolls/buns', 'soda'],
 ['citrus_fruit', 'other_vegetables', 'pip_fruit', 'tropical_fruit'],
 ['artif._sweetener',
  'bottled_water',
  'domestic_eggs',
  'shopping_bags',
  'sliced_cheese',
  'soda',
  'whole_milk'],
 ['bottled_beer', 'pastry', 'soda'],
 ['coffee',
  'curd_cheese',
  'frozen_vegetables',
  'fruit/vegetable_juice',
  'hard_cheese',
  'hygiene_articles',
  'ice_cream',
  'other_vegetables',
  'pastry',
  'soft_cheese',
  'spread_cheese',
  'tropical_fruit',
  'whole_milk',
  'yogurt'],
 ['newspapers', 'pastry', 'sliced_cheese'],
 ['soda'],
 ['citrus_fruit',
  'coffee',
  'dessert',
  'frozen_meals',
  'ham',
  'popcorn',
  'shopping_bags',
  'whole_milk'],
 ['salty_snack'],
 ['bottled_water',
  'coffee',
  'cream_cheese_',
  'curd',
  'flour',
  'misc._beverages',
  'newspapers',
  'whole_milk'],
 ['root_vegetables', 'whipped/sour_cream'],
 ['canned_beer', 'shopping_bags', 'soda'],
 ['bottled_water',
  'canned_beer',
  'curd',
  'dish_cleaner',
  'margarine',
  'roll_products_',
  'white_wine'],
 ['bottled_beer', 'bottled_water', 'fruit/vegetable_juice', 'napkins', 'soda'],
 ['packaged_fruit/vegetables', 'pot_plants'],
 ['bottled_water',
  'cling_film/bags',
  'frozen_vegetables',
  'ice_cream',
  'root_vegetables',
  'tropical_fruit'],
 ['beef',
  'bottled_water',
  'chocolate',
  'domestic_eggs',
  'fruit/vegetable_juice',
  'grapes',
  'ham',
  'newspapers',
  'pastry',
  'salty_snack',
  'shopping_bags',
  'whipped/sour_cream',
  'white_bread',
  'white_wine',
  'yogurt'],
 ['UHT-milk',
  'bottled_beer',
  'brown_bread',
  'canned_beer',
  'citrus_fruit',
  'long_life_bakery_product',
  'pork',
  'soda'],
 ['beverages', 'cake_bar', 'liqueur', 'misc._beverages', 'rolls/buns', 'soda'],
 ['rolls/buns', 'sausage', 'soda'],
 ['bottled_water',
  'citrus_fruit',
  'napkins',
  'rolls/buns',
  'sausage',
  'soda',
  'whole_milk',
  'yogurt'],
 ['butter',
  'cream_cheese_',
  'frozen_fish',
  'root_vegetables',
  'shopping_bags',
  'whole_milk',
  'yogurt'],
 ['cream_cheese_', 'whole_milk'],
 ['frankfurter',
  'other_vegetables',
  'pastry',
  'ready_soups',
  'rolls/buns',
  'root_vegetables',
  'turkey',
  'yogurt'],
 ['shopping_bags', 'soda'],
 ['bottled_beer', 'soda'],
 ['frankfurter', 'popcorn'],
 ['berries',
  'detergent',
  'newspapers',
  'pickled_vegetables',
  'whipped/sour_cream',
  'whole_milk'],
 ['canned_beer'],
 ['canned_vegetables', 'frankfurter', 'pork', 'soda', 'white_bread'],
 ['butter',
  'chocolate',
  'chocolate_marshmallow',
  'curd',
  'dental_care',
  'dish_cleaner',
  'flour',
  'frankfurter',
  'hamburger_meat',
  'mustard',
  'oil',
  'rice',
  'salty_snack',
  'sugar',
  'whole_milk'],
 ['berries',
  'beverages',
  'coffee',
  'root_vegetables',
  'shopping_bags',
  'soups',
  'sugar',
  'whole_milk'],
 ['frankfurter', 'rolls/buns'],
 ['newspapers'],
 ['frozen_fish', 'newspapers'],
 ['newspapers', 'tropical_fruit'],
 ['beef',
  'berries',
  'grapes',
  'newspapers',
  'pot_plants',
  'rolls/buns',
  'whole_milk',
  'yogurt'],
 ['coffee',
  'instant_coffee',
  'rolls/buns',
  'salty_snack',
  'specialty_chocolate'],
 ['pot_plants', 'specialty_chocolate'],
 ['dish_cleaner', 'sparkling_wine'],
 ['citrus_fruit', 'napkins', 'shopping_bags'],
 ['bottled_beer', 'herbs', 'onions'],
 ['candles', 'detergent', 'pastry', 'whole_milk'],
 ['photo/film'],
 ['hamburger_meat'],
 ['chewing_gum', 'other_vegetables', 'white_bread', 'whole_milk'],
 ['rolls/buns', 'shopping_bags', 'whole_milk'],
 ['grapes',
  'hard_cheese',
  'napkins',
  'pork',
  'shopping_bags',
  'soda',
  'tropical_fruit'],
 ['baking_powder',
  'berries',
  'bottled_water',
  'butter',
  'canned_beer',
  'dessert',
  'fruit/vegetable_juice',
  'grapes',
  'ice_cream',
  'misc._beverages',
  'other_vegetables',
  'pastry',
  'pot_plants',
  'salt',
  'specialty_chocolate',
  'tropical_fruit',
  'whipped/sour_cream',
  'whole_milk',
  'yogurt'],
 ['chewing_gum',
  'chicken',
  'citrus_fruit',
  'other_vegetables',
  'pork',
  'pot_plants',
  'whipped/sour_cream',
  'white_bread'],
 ['chewing_gum', 'other_vegetables'],
 ['bottled_water', 'red/blush_wine', 'sausage'],
 ['baking_powder', 'whipped/sour_cream', 'whole_milk'],
 ['coffee', 'rolls/buns'],
 ['hygiene_articles'],
 ['ice_cream', 'newspapers'],
 ['curd',
  'domestic_eggs',
  'flour',
  'misc._beverages',
  'newspapers',
  'whipped/sour_cream'],
 ['frozen_meals', 'newspapers', 'whole_milk'],
 ['bottled_water',
  'coffee',
  'dessert',
  'domestic_eggs',
  'onions',
  'rolls/buns',
  'white_bread',
  'whole_milk'],
 ['finished_products',
  'fruit/vegetable_juice',
  'organic_sausage',
  'sliced_cheese',
  'white_bread'],
 ['dog_food', 'long_life_bakery_product', 'salt'],
 ['brown_bread',
  'canned_vegetables',
  'domestic_eggs',
  'fruit/vegetable_juice',
  'other_vegetables',
  'root_vegetables',
  'rum',
  'soda',
  'tropical_fruit',
  'white_bread'],
 ['other_vegetables', 'whole_milk', 'yogurt'],
 ['chocolate'],
 ['ice_cream'],
 ['cat_food', 'oil', 'tropical_fruit'],
 ['citrus_fruit',
  'frankfurter',
  'fruit/vegetable_juice',
  'pastry',
  'sliced_cheese',
  'specialty_cheese',
  'whole_milk',
  'yogurt'],
 ['butter', 'canned_fish', 'flower_(seeds)', 'pasta', 'softener'],
 ['butter_milk', 'frozen_fish', 'other_vegetables', 'salty_snack'],
 ['canned_beer', 'chocolate', 'pastry', 'tropical_fruit'],
 ['brown_bread',
  'citrus_fruit',
  'packaged_fruit/vegetables',
  'rolls/buns',
  'root_vegetables',
  'sliced_cheese',
  'white_bread',
  'yogurt',
  'zwieback'],
 ['UHT-milk', 'salt', 'shopping_bags', 'soda', 'specialty_chocolate'],
 ['beef'],
 ['canned_vegetables', 'curd', 'spread_cheese', 'sugar', 'yogurt'],
 ['bottled_beer',
  'citrus_fruit',
  'dessert',
  'frozen_vegetables',
  'fruit/vegetable_juice',
  'other_vegetables',
  'salty_snack',
  'whole_milk',
  'yogurt'],
 ['bottled_beer', 'brown_bread', 'white_wine', 'yogurt'],
 ['bottled_beer', 'liquor', 'red/blush_wine'],
 ['grapes'],
 ['other_vegetables', 'pork', 'soda'],
 ['berries',
  'candy',
  'canned_fish',
  'chocolate',
  'citrus_fruit',
  'cream_cheese_',
  'domestic_eggs',
  'frozen_vegetables',
  'margarine',
  'napkins',
  'other_vegetables',
  'pastry',
  'sausage',
  'soups',
  'whipped/sour_cream',
  'whole_milk',
  'yogurt'],
 ['UHT-milk',
  'brown_bread',
  'chicken',
  'chocolate',
  'cocoa_drinks',
  'coffee',
  'flour',
  'frankfurter',
  'fruit/vegetable_juice',
  'long_life_bakery_product',
  'mayonnaise',
  'mustard',
  'other_vegetables',
  'pastry',
  'pork',
  'root_vegetables',
  'salty_snack',
  'seasonal_products',
  'tropical_fruit',
  'yogurt'],
 ['artif._sweetener', 'photo/film', 'soda'],
 ['bottled_beer',
  'butter',
  'coffee',
  'frankfurter',
  'onions',
  'processed_cheese',
  'rolls/buns'],
 ['dessert',
  'domestic_eggs',
  'pip_fruit',
  'root_vegetables',
  'shopping_bags',
  'yogurt'],
 ['coffee', 'detergent', 'frankfurter', 'whole_milk'],
 ['newspapers', 'whole_milk'],
 ['domestic_eggs', 'flower_soil/fertilizer', 'hygiene_articles', 'photo/film'],
 ['chocolate',
  'dessert',
  'flower_(seeds)',
  'mayonnaise',
  'oil',
  'packaged_fruit/vegetables',
  'shopping_bags',
  'soda',
  'waffles'],
 ['bottled_water',
  'chicken',
  'frozen_vegetables',
  'long_life_bakery_product',
  'other_vegetables',
  'whipped/sour_cream'],
 ['baking_powder',
  'candy',
  'cocoa_drinks',
  'coffee',
  'cream_cheese_',
  'curd',
  'domestic_eggs',
  'napkins',
  'pork',
  'salty_snack',
  'sugar',
  'waffles',
  'whipped/sour_cream',
  'white_bread',
  'whole_milk',
  'yogurt'],
 ['citrus_fruit',
  'cleaner',
  'coffee',
  'cream_cheese_',
  'curd',
  'detergent',
  'long_life_bakery_product',
  'napkins',
  'newspapers',
  'oil',
  'other_vegetables',
  'pastry',
  'vinegar',
  'whipped/sour_cream',
  'whole_milk',
  'yogurt'],
 ['light_bulbs'],
 ['cream_cheese_', 'margarine', 'tea'],
 ['cake_bar',
  'cleaner',
  'curd',
  'detergent',
  'domestic_eggs',
  'frozen_meals',
  'house_keeping_products',
  'pot_plants',
  'sausage',
  'seasonal_products',
  'shopping_bags'],
 ['citrus_fruit', 'onions'],
 ['other_vegetables', 'roll_products_', 'whipped/sour_cream'],
 ['bottled_water',
  'butter',
  'chicken',
  'cling_film/bags',
  'dog_food',
  'domestic_eggs',
  'frozen_fish',
  'frozen_vegetables',
  'fruit/vegetable_juice',
  'hard_cheese',
  'long_life_bakery_product',
  'napkins',
  'other_vegetables',
  'pip_fruit',
  'rice',
  'root_vegetables',
  'softener',
  'specialty_fat',
  'tropical_fruit',
  'whipped/sour_cream',
  'white_bread',
  'whole_milk',
  'yogurt'],
 ['ice_cream'],
 ['beef', 'ice_cream', 'newspapers', 'pork', 'rolls/buns'],
 ['artif._sweetener',
  'chocolate_marshmallow',
  'flour',
  'margarine',
  'organic_products',
  'other_vegetables',
  'pork',
  'semi-finished_bread',
  'tropical_fruit',
  'yogurt'],
 ...]

In [5]:
def frequent_itemsets(sentences):
    # Counts sets with Apriori algorithm.
    SUPP_THRESHOLD = 100
    supps = []
 
    supp = {}
    for sentence in sentences:
        for key in sentence:
            if key in supp:
                supp[key] += 1
            else:
                supp[key] = 1
    print ("|C1| = " + str(len(supp)))
    supps.append({k:v for k,v in supp.items() if v >= SUPP_THRESHOLD})
    print ("|L1| = " + str(len(supps[0])))
 
    supp = {}
    for sentence in sentences:
        for combination in itertools.combinations(sentence, 2):
            if combination[0] in supps[0] and combination[1] in supps[0]:
                key = ','.join(combination)
                if key in supp:
                    supp[key] += 1
                else:
                    supp[key] = 1
    print ("|C2| = " + str(len(supp)))
    supps.append({k:v for k,v in supp.items() if v >= SUPP_THRESHOLD})
    print ("|L2| = " + str(len(supps[1])))
 
    supp = {}
    for sentence in sentences:
        for combination in itertools.combinations(sentence, 3):
            if (combination[0]+','+combination[1] in supps[1] and
                    combination[0]+','+combination[2] in supps[1] and
                    combination[1]+','+combination[2] in supps[1]):
                key = ','.join(combination)
                if key in supp:
                    supp[key] += 1
                else:
                    supp[key] = 1
    print ("|C3| = " + str(len(supp)))
    supps.append({k:v for k,v in supp.items() if v >= SUPP_THRESHOLD})
    print ("|L3| = " + str(len(supps[2])))
 
    return supps

In [6]:
def measures(supp_ab, supp_a, supp_b, transaction_count):
    # Assumes A -> B, where A and B are sets.
    conf = float(supp_ab) / float(supp_a)
    s = float(supp_b) / float(transaction_count)
    lift = conf / s
    if conf == 1.0:
        conv = float('inf')
    else:
        conv = (1-s) / (1-conf)
    return [conf, lift, conv]

In [7]:
def generate_rules(measure, supps, transaction_count):
    rules = []
    CONF_THRESHOLD = 0.4
    LIFT_THRESHOLD = 20.0
    CONV_THRESHOLD = 5.0
    if measure == 'conf':
        for i in range(2, len(supps)+1):
            for k,v in supps[i-1].items():
                k = k.split(',')
                for j in range(1, len(k)):
                    for a in itertools.combinations(k, j):
                        b = tuple([w for w in k if w not in a])
                        [conf, lift, conv] = measures(v,
                                supps[len(a)-1][','.join(a)],
                                supps[len(b)-1][','.join(b)],
                                transaction_count)
                        if conf >= CONF_THRESHOLD:
                            rules.append((a, b, conf, lift, conv))
            rules = sorted(rules, key=lambda x: (x[0], x[1]))
            rules = sorted(rules, key=lambda x: (x[2]), reverse=True)
    elif measure == 'lift':
        for i in range(2, len(supps)+1):
            for k,v in supps[i-1].items():
                k = k.split(',')
                for j in range(1, len(k)):
                    for a in itertools.combinations(k, j):
                        b = tuple([w for w in k if w not in a])
                        [conf, lift, conv] = measures(v,
                                supps[len(a)-1][','.join(a)],
                                supps[len(b)-1][','.join(b)],
                                transaction_count)
                        if lift >= LIFT_THRESHOLD:
                            rules.append((a, b, conf, lift, conv))
            rules = sorted(rules, key=lambda x: (x[0], x[1]))
            rules = sorted(rules, key=lambda x: (x[3]), reverse=True)
    elif measure == 'conv':
        for i in range(2, len(supps)+1):
            for k,v in supps[i-1].items():
                k = k.split(',')
                for j in range(1, len(k)):
                    for a in itertools.combinations(k, j):
                        b = tuple([w for w in k if w not in a])
                        [conf, lift, conv] = measures(v,
                                supps[len(a)-1][','.join(a)],
                                supps[len(b)-1][','.join(b)],
                                transaction_count)
                        if conv >= CONV_THRESHOLD:
                            rules.append((a, b, conf, lift, conv))
            rules = sorted(rules, key=lambda x: (x[0], x[1]))
            rules = sorted(rules, key=lambda x: (x[4]), reverse=True)
    else:
        for i in range(2, len(supps)+1):
            for k,v in supps[i-1].items():
                k = k.split(',')
                for j in range(1, len(k)):
                    for a in itertools.combinations(k, j):
                        b = tuple([w for w in k if w not in a])
                        [conf, lift, conv] = measures(v,
                                supps[len(a)-1][','.join(a)],
                                supps[len(b)-1][','.join(b)],
                                transaction_count)
                        if (conf >= CONF_THRESHOLD and
                                lift >= LIFT_THRESHOLD and
                                conv >= CONV_THRESHOLD):
                            rules.append((a, b, conf, lift, conv))
            rules = sorted(rules, key=lambda x: (x[0], x[1]))
            rules = sorted(rules, key=lambda x: (x[2],x[3],x[4]), reverse=True)
    return rules

In [8]:
def main(file, measure): 
    sentences = tokenize(file)
 
    start_time = time.time()
    supps = frequent_itemsets(sentences)
    end_time = time.time()
    print ("Time spent finding frequent itemsets = {:.2f} seconds.".format(
          end_time - start_time))
 
    start_time = time.time()
    rules = generate_rules(measure, supps, len(sentences))
    for rule in rules:
        print (("{{{}}} -> {{{}}}, "
               "conf = {:.2f}, lift = {:.2f}, conv = {:.2f}").format(
              ', '.join(rule[0]), ', '.join(rule[1]), rule[2], rule[3], rule[4]))
    end_time = time.time()
    print ("Time spent finding association rules = {:.2f} second.".format(
          end_time - start_time))
 
if __name__ == "__main__":
    measure = 'all'
    #measure could be all, conf, lift or conv
    file = "../data/groceries_mba.csv"
    main(file, "conf")


|C1| = 170
|L1| = 88
|C2| = 3781
|L2| = 207
|C3| = 548
|L3| = 31
Time spent finding frequent itemsets = 0.30 seconds.
{citrus_fruit, root_vegetables} -> {other_vegetables}, conf = 0.59, lift = 3.03, conv = 1.95
{root_vegetables, tropical_fruit} -> {other_vegetables}, conf = 0.58, lift = 3.02, conv = 1.94
{butter, other_vegetables} -> {whole_milk}, conf = 0.57, lift = 2.25, conv = 1.75
{root_vegetables, tropical_fruit} -> {whole_milk}, conf = 0.57, lift = 2.23, conv = 1.73
{root_vegetables, yogurt} -> {whole_milk}, conf = 0.56, lift = 2.20, conv = 1.70
{domestic_eggs, other_vegetables} -> {whole_milk}, conf = 0.55, lift = 2.16, conv = 1.66
{whipped/sour_cream, yogurt} -> {whole_milk}, conf = 0.52, lift = 2.05, conv = 1.57
{rolls/buns, root_vegetables} -> {whole_milk}, conf = 0.52, lift = 2.05, conv = 1.56
{other_vegetables, pip_fruit} -> {whole_milk}, conf = 0.52, lift = 2.03, conv = 1.54
{tropical_fruit, yogurt} -> {whole_milk}, conf = 0.52, lift = 2.02, conv = 1.54
{other_vegetables, yogurt} -> {whole_milk}, conf = 0.51, lift = 2.01, conv = 1.53
{other_vegetables, whipped/sour_cream} -> {whole_milk}, conf = 0.51, lift = 1.98, conv = 1.51
{rolls/buns, root_vegetables} -> {other_vegetables}, conf = 0.50, lift = 2.60, conv = 1.62
{root_vegetables, yogurt} -> {other_vegetables}, conf = 0.50, lift = 2.58, conv = 1.61
{fruit/vegetable_juice, other_vegetables} -> {whole_milk}, conf = 0.50, lift = 1.95, conv = 1.48
{butter} -> {whole_milk}, conf = 0.50, lift = 1.95, conv = 1.48
{curd} -> {whole_milk}, conf = 0.49, lift = 1.92, conv = 1.46
{whipped/sour_cream, yogurt} -> {other_vegetables}, conf = 0.49, lift = 2.53, conv = 1.58
{other_vegetables, root_vegetables} -> {whole_milk}, conf = 0.49, lift = 1.92, conv = 1.46
{other_vegetables, tropical_fruit} -> {whole_milk}, conf = 0.48, lift = 1.86, conv = 1.42
{citrus_fruit, yogurt} -> {whole_milk}, conf = 0.47, lift = 1.86, conv = 1.42
{root_vegetables, whole_milk} -> {other_vegetables}, conf = 0.47, lift = 2.45, conv = 1.53
{domestic_eggs} -> {whole_milk}, conf = 0.47, lift = 1.85, conv = 1.41
{other_vegetables, pork} -> {whole_milk}, conf = 0.47, lift = 1.84, conv = 1.40
{other_vegetables, pastry} -> {whole_milk}, conf = 0.47, lift = 1.83, conv = 1.40
{onions} -> {other_vegetables}, conf = 0.46, lift = 2.37, conv = 1.49
{pork, whole_milk} -> {other_vegetables}, conf = 0.46, lift = 2.37, conv = 1.49
{whipped/sour_cream, whole_milk} -> {other_vegetables}, conf = 0.45, lift = 2.35, conv = 1.48
{rolls/buns, yogurt} -> {whole_milk}, conf = 0.45, lift = 1.77, conv = 1.36
{citrus_fruit, other_vegetables} -> {whole_milk}, conf = 0.45, lift = 1.76, conv = 1.36
{whipped/sour_cream} -> {whole_milk}, conf = 0.45, lift = 1.76, conv = 1.35
{pip_fruit, whole_milk} -> {other_vegetables}, conf = 0.45, lift = 2.32, conv = 1.46
{root_vegetables} -> {whole_milk}, conf = 0.45, lift = 1.76, conv = 1.35
{rolls/buns, tropical_fruit} -> {whole_milk}, conf = 0.45, lift = 1.75, conv = 1.34
{sugar} -> {whole_milk}, conf = 0.44, lift = 1.74, conv = 1.34
{hamburger_meat} -> {whole_milk}, conf = 0.44, lift = 1.74, conv = 1.34
{ham} -> {whole_milk}, conf = 0.44, lift = 1.73, conv = 1.33
{sliced_cheese} -> {whole_milk}, conf = 0.44, lift = 1.72, conv = 1.33
{root_vegetables} -> {other_vegetables}, conf = 0.43, lift = 2.25, conv = 1.43
{bottled_water, other_vegetables} -> {whole_milk}, conf = 0.43, lift = 1.70, conv = 1.32
{citrus_fruit, whole_milk} -> {other_vegetables}, conf = 0.43, lift = 2.21, conv = 1.41
{other_vegetables, soda} -> {whole_milk}, conf = 0.43, lift = 1.67, conv = 1.30
{frozen_vegetables} -> {whole_milk}, conf = 0.42, lift = 1.66, conv = 1.29
{tropical_fruit, yogurt} -> {other_vegetables}, conf = 0.42, lift = 2.17, conv = 1.39
{other_vegetables, rolls/buns} -> {whole_milk}, conf = 0.42, lift = 1.64, conv = 1.28
{chicken} -> {other_vegetables}, conf = 0.42, lift = 2.16, conv = 1.38
{butter, whole_milk} -> {other_vegetables}, conf = 0.42, lift = 2.16, conv = 1.38
{hamburger_meat} -> {other_vegetables}, conf = 0.42, lift = 2.15, conv = 1.38
{cream_cheese_} -> {whole_milk}, conf = 0.42, lift = 1.63, conv = 1.27
{butter_milk} -> {whole_milk}, conf = 0.41, lift = 1.62, conv = 1.27
{margarine} -> {whole_milk}, conf = 0.41, lift = 1.62, conv = 1.27
{domestic_eggs, whole_milk} -> {other_vegetables}, conf = 0.41, lift = 2.12, conv = 1.37
{chicken} -> {whole_milk}, conf = 0.41, lift = 1.60, conv = 1.26
{white_bread} -> {whole_milk}, conf = 0.41, lift = 1.59, conv = 1.25
{beef} -> {whole_milk}, conf = 0.41, lift = 1.59, conv = 1.25
{tropical_fruit, whole_milk} -> {other_vegetables}, conf = 0.40, lift = 2.09, conv = 1.35
{tropical_fruit} -> {whole_milk}, conf = 0.40, lift = 1.58, conv = 1.25
{whipped/sour_cream} -> {other_vegetables}, conf = 0.40, lift = 2.08, conv = 1.35
{oil} -> {whole_milk}, conf = 0.40, lift = 1.57, conv = 1.25
{yogurt} -> {whole_milk}, conf = 0.40, lift = 1.57, conv = 1.24
Time spent finding association rules = 0.00 second.

Exercise 1 Try changing the parameters (measure and threshold) and get rules


In [ ]: